Suppose I do this
import cmath
del cmath
cmath.sqrt(-1)
I get this
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'cmath' is not defined
But when I import cmath again, I am able to use sqrt again
import cmath
cmath.sqrt(-1)
1j
But when I do the following
import cmath
del cmath.sqrt
cmath.sqrt(-1)
I get this
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'sqrt'
Even when I import cmath again, I get the same error.
Is it possible to get cmath.sqrt back?
Thanks!
You'd need reload
reload(cmath)
... will reload definitions from the module.
import cmath
del cmath.sqrt
reload(cmath)
cmath.sqrt(-1)
... will correctly print ..
1j
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With