REPL - recover callable after redefining it

92 views Asked by At

I doing some work inside the Python REPL and I redefined one of the primitive callable's.

i.e list = [] will prevent tuple = list((1,2,3)) from working anymore.

Aside from restarting the REPL is there a way to 'recover' or reassign list to its default value?

Maybe there is an import or a super class? Or would it be forever lost and stuck with what I assigned it until I restart the REPL?

1

There are 1 answers

7
Padraic Cunningham On BEST ANSWER

You can delete the name 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]: []

Or 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]: []

For 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]: []