Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

overwriting list keyword in python [duplicate]

Tags:

python

I coded a short linked list program in Python, but without realizing list was a keyword in python, I stored my LinkedList object into list

list = LinkedList()

Running this program worked fine, but now I'm running into issues in another program where I need the list keyword to be used normally, but it still contains a reference to the LinkedList object and not the proper keyword functionality. I have since gone back to my LinkedList class and edited list to be lst instead, but I still have the same error in the class that uses the list keyword. How do I reset the list keyword to its original value?

This is the line that is giving me an error:

df = pd.DataFrame(randn(6,4), index = dates, columns = list("ABCD"))

And this is the error message:

TypeError: 'LinkedList' object is not callable

like image 310
Joel Katz Avatar asked Apr 09 '26 17:04

Joel Katz


1 Answers

It's almost certainly better to stop shadowing builtins, as Kroltan says in his comment, but as the Python quote goes

we are all consenting adults here

so…

>>> list='axe'
>>> __builtins__.list('abc')
['a', 'b', 'c']

Also, for fun, you can convert a literal to its type function using the type function.

>>> list='chuck testa'
>>> type([])('abc')
['a', 'b', 'c']
>>> type(3)(10.5)
10

etc

like image 197
kojiro Avatar answered Apr 12 '26 07:04

kojiro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!