这是怎么回事?为什么解开这个地图对象的打印“必须是可迭代的,而不是地图”?
>>> list(map(lambda *x: x, *map(None, 'abc')))
Traceback (most recent call last):
File "<pyshell#52>", line 1, in <module>
list(map(lambda *x: x, *map(None, 'abc')))
TypeError: type object argument after * must be an iterable, not map
忽略代码的毫无意义。这是关于错误消息,“可迭代,不映射”。地图是可迭代的,他们不是?
如果我只用str
取代None
,整个事情正常工作:
>>> list(map(lambda *x: x, *map(str, 'abc')))
[('a', 'b', 'c')]
所以现在Python没有任何问题与map
那里毕竟。
这发生在我的Python 3.6.1中。我的Python 3.5.2反而提高了预期的TypeError: 'NoneType' object is not callable
。并且使用google搜索"must be an iterable, not map"根本找不到结果。所以显然这是最近才引入的。
这只是一个Python bug?还是有一些意义呢?
更新:Reported as bug现在,建议。
'打开一个bug“我的Python 3.5.2,而不是引发预期的类型错误:‘NoneType’对象不是可调用的”'这是奇怪的。在我的Python 3.4.4上,我得到(几乎)和3.6一样的错误:'TypeError:*之后的类型对象参数必须是一个序列,而不是映射' – DeepSpace
有趣。我只是做了'm = map(None,'abc')'然后试图做'def f(* args):print(args); f(* m)'和Python引发了一个'TypeError:'NoneType'对象不可调用。 –
消息在提交中已更新:https://github.com/python/cpython/commit/7344285c1919e5ade8016a83a3ee02fd637a030d –