3
假如我這樣做如何恢復已刪除的庫函數?
import cmath
del cmath
cmath.sqrt(-1)
我得到這個
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'cmath' is not defined
但是,當我再次導入cmath
,我能夠再次使用sqrt
import cmath
cmath.sqrt(-1)
1j
但是當我做了以下
import cmath
del cmath.sqrt
cmath.sqrt(-1)
我得到這個
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'sqrt'
即使當我輸入cmath
,我再次得到了同樣的錯誤。
是否有可能得到cmath.sqrt
?
謝謝!
爲什麼要那樣做? – detly 2011-04-08 09:00:27
@detly - 沒有意圖。我只是在學習Python,而我正在使用交互式編譯器。 – bdhar 2011-04-08 10:51:26