1

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

Thomas K
  • 39,200
  • 7
  • 84
  • 86
Koci Kocev
  • 79
  • 2
  • 2
  • 7
  • can you post your code too – Hackaholic Jan 09 '15 at 07:20
  • You are overriding the function with range by assigning it None and then trying to call range which is not a function object but its of NoneType which you can't call. – Tanveer Alam Jan 09 '15 at 07:22
  • Have you seen this? Can't try it out myself but might work for you. http://stackoverflow.com/questions/4599016/are-the-python-built-in-methods-available-in-an-alternative-namespace-anywhere – zehnpaard Jan 09 '15 at 07:23
  • Thanks, del solved it and __builtin__ is great if you want to keep the variable. I will add my code as well. – Koci Kocev Jan 09 '15 at 07:28

1 Answers1

4

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>
Stephen Lin
  • 4,852
  • 1
  • 13
  • 26