delI seem to have a memory that puzzles me. See the following:
In [1]: import math
In [2]: math.cos(0)
Out[2]: 1.0
In [3]: del math.cos
In [4]: math.cos(0)
AttributeError Traceback (most recent call last)
<ipython-input-4-9cdcc157d079> in <module>()
AttributeError: module 'math' has no attribute 'cos'
Fine Let's see what happens if we remove the entire math package:
In [5]: del math
In [6]: math.cos(0)
NameError Traceback (most recent call last)
<ipython-input-6-9cdcc157d079> in <module>()
NameError: name 'math' is not defined
So, now the math itself is gone, as expected.
Now import the math again:
In [7]: import math
In [8]: math.cos(0)
AttributeError Traceback (most recent call last)
<ipython-input-8-9cdcc157d079> in <module>()
AttributeError: module 'math' has no attribute 'cos'
So, somehow interactive python remembers that math.cos was specifically deleted even after we removed the entire math package and imported it again.
Where does python store this knowledge? Can we access it? Can we change it?
source
share