为什么python中的list(None)在不同的终端中给出不同的异常?

时间:2015-09-16 14:28:21

标签: python list python-2.7 nonetype

我正在使用Python 2.7编写游戏,在调试时发现了一个我无法在Python控制台中重现的异常。 在脚本的某个时刻,我使用了list()函数并在返回另一个函数时使用它,如:

var1 = list(otherfunction(arg1, arg2, andsoon))

当其他函数返回None时,我得到了异常:

TypeError: 'NoneType' object is not iterable

但是当我在Python控制台的新终端中查看它时,我得到了:

>>> newlist = list(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable

然后我在终端窗口启动了一个控制台,我运行了脚本并再次尝试:

>>> newlist = list(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not iterable

为什么翻译给我不同的例外是否有充分的理由?或者这些例外(不可调用且不可迭代)是否可以互换并且是无关紧要的区别?

对于我的脚本这没关系,我只想了解什么可能导致(看似)在不同终端窗口中的相同操作的不同异常。

可能相关的一些额外系统信息:

Python 2.7.10 (default, Jul  5 2015, 14:15:43) 
[GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux2

0 个答案:

没有答案