我在Python REPL中做了一些工作,并重新定义了一个原始的可调用的。
即list = []
将阻止tuple = list((1,2,3))
再次工作。
除了重新启动REPL之外,有一种方法可以恢复'或将列表重新分配给其默认值?
也许有导入或超类?或者它会永远丢失并坚持使用我指定的内容,直到我重新启动REPL?
答案 0 :(得分:6)
您可以删除名称del list
In [9]: list = []
In [10]: list()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-10-8b11f83c3293> in <module>()
----> 1 list()
TypeError: 'list' object is not callable
In [11]: del list
In [12]: list()
Out[12]: []
或list = builtins.list
for python3:
In [10]: import builtins
In [11]: list = []
In [12]: list()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-12-8b11f83c3293> in <module>()
----> 1 list()
TypeError: 'list' object is not callable
In [13]: list = builtins.list
In [14]: list()
Out[14]: []
对于python 2:
In [1]: import __builtin__
In [2]: list = []
In [3]: list()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-8b11f83c3293> in <module>()
----> 1 list()
TypeError: 'list' object is not callable
In [4]: list = __builtin__.list
In [5]: list()
Out[5]: []