Python variable named range hides range() function in terminal

Question:

I am using Python 2.7.3 and IPython 0.12.1 and while in terminal I initialized a variable named range. I don’t won’t to restart the session and I want to use the range function. I tried to set the variable to None, but then I get the following error when I try to call range():

range = [1,2,3]
range = None
range(0,3000,5)

TypeError: ‘NoneType’ object is not callable

Asked By: Koci Kocev

||

Answers:

You have to delete range variable to get built-in function back but not give it a none.

Like this:

>>> range
<built-in function range>
>>> range = 1
>>> range
1
>>> del range
>>> range
<built-in function range>
Answered By: Stephen Lin
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.