2006年07月05日 星期三 18:37
以下程序为什么错? >>> q ['11 1 5 5', '22 5 5 1', '103 1 15 10', '114 10 15 1', '12 2 20 2'] >>> q[0].split() ['11', '1', '5', '5'] >>> w=map(int,q[0].split()) Traceback (most recent call last): File "", line 1, in ? TypeError: 'tuple' object is not callable 我查了map >>> map 但是奇怪的是我没有命名过任何map的东西. 如果我还是想用map 的功能,怎么办?
2006年07月05日 星期三 18:58
On 7/5/06, linda. s <samrobertsmith at gmail.com> wrote: > 以下程序为什么错? > >>> q > ['11 1 5 5', '22 5 5 1', '103 1 15 10', '114 10 15 1', '12 2 20 2'] > >>> q[0].split() > ['11', '1', '5', '5'] > >>> w=map(int,q[0].split()) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: 'tuple' object is not callable 奇怪,在我这里是对的嘛: >>> q = ['11 1 5 5', '22 5 5 1', '103 1 15 10', '114 10 15 1', '12 2 20 2'] >>> w = map(int, q[0].split()) >>> w [11, 1, 5, 5] >>> -- Best Regards, Leo Jay
2006年07月05日 星期三 19:04
你自己给出的操作已经解释了这个问题,仔细看看那个信息你就明白,map是Python的内置函数,用于对线形容器执行函数化操作,具体来说,是把对某个(或多个)序列中所有元素的操作结果映射到另一个序列中。 >>> help(map) Help on built-in function map in module __builtin__: map(...) map(function, sequence[, sequence, ...]) -> list Return a list of the results of applying the function to the items of the argument sequence(s). If more than one sequence is given, the function is called with an argument list consisting of the corresponding item of each sequence, substituting None for missing values when not all sequences have the same length. If the function is None, return a list of the items of the sequence (or a list of tuples if more than one sequence). help用起来很方便,要善于利用,map的用法在tut里有,Python自带的官方教程。并不长,建议初学者都读一读。 -- 欢迎访问: http://blog.csdn.net/ccat 刘鑫 March.Liu -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060705/78bf51ab/attachment.html
2006年07月05日 星期三 19:05
你的 int 和 map 是不是被你赋值了? On 7/5/06, Leo Jay <python.leojay at gmail.com> wrote: > On 7/5/06, linda. s <samrobertsmith at gmail.com> wrote: > > 以下程序为什么错? > > >>> q > > ['11 1 5 5', '22 5 5 1', '103 1 15 10', '114 10 15 1', '12 2 20 2'] > > >>> q[0].split() > > ['11', '1', '5', '5'] > > >>> w=map(int,q[0].split()) > > Traceback (most recent call last): > > File "", line 1, in ? > > TypeError: 'tuple' object is not callable > > > 奇怪,在我这里是对的嘛: > >>> q = ['11 1 5 5', '22 5 5 1', '103 1 15 10', '114 10 15 1', '12 2 20 2'] > >>> w = map(int, q[0].split()) > >>> w > [11, 1, 5, 5] > >>> > > -- > Best Regards, > Leo Jay > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > >
2006年07月05日 星期三 19:08
不用 map也行阿 , [int(c) for c in q[0].split()] 比用map清晰 On 7/5/06, Dreamingk(天成) <dreamingk at gmail.com> wrote: > 你的 int 和 map 是不是被你赋值了? > > On 7/5/06, Leo Jay <python.leojay at gmail.com> wrote: > > On 7/5/06, linda. s <samrobertsmith at gmail.com> wrote: > > > 以下程序为什么错? > > > >>> q > > > ['11 1 5 5', '22 5 5 1', '103 1 15 10', '114 10 15 1', '12 2 20 2'] > > > >>> q[0].split() > > > ['11', '1', '5', '5'] > > > >>> w=map(int,q[0].split()) > > > Traceback (most recent call last): > > > File "", line 1, in ? > > > TypeError: 'tuple' object is not callable > > > > > > 奇怪,在我这里是对的嘛: > > >>> q = ['11 1 5 5', '22 5 5 1', '103 1 15 10', '114 10 15 1', '12 2 20 2'] > > >>> w = map(int, q[0].split()) > > >>> w > > [11, 1, 5, 5] > > >>> > > > > -- > > Best Regards, > > Leo Jay > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese at lists.python.cn > > Subscribe: send subscribe to python-chinese-request at lists.python.cn > > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > >
Zeuux © 2025
京ICP备05028076号