我删除了ipython上的(包内置)函数:
Python 3.6.4 |Anaconda custom (64-bit)| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.
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>()
----> 1 math.cos(0)
AttributeError: module 'math' has no attribute 'cos'
好吧。但是如何重新加载函数呢?这没用:
^{pr2}$
好吧,各位,我写了一个小模块来解决这个困惑。 我真诚地怀疑这是没有错误的。因此,改进是受欢迎的。在
这个模块在py2和py3上都能很好地工作。尝试了Python2.7和Python3.5。在
上面的代码适用于Windows上的Python3.4,但3.6的documentation是这样的:
(所以也许我只是“幸运”)
所以可以肯定的是:
你甚至不需要它。只需从缓存中删除并再次导入。在
如注释中所述,使用
^{pr2}$reload
也可以,但是您需要更新reload
给出的模块引用,而不仅仅是重用丢失了cos
项的同一旧引用:相关问题 更多 >
编程相关推荐