SciPy 的网站有一个引用 python 函数 source
的教程,其中列出了用 python 编写的函数的源代码,但我无法在 python 中使用它或在线找到它的文档。引用在this底部页。我看到 inspect
模块具有类似的功能,但我仍然很好奇它们引用的是哪个模块中的哪个函数。
最佳答案
np.source
是 numpy
中的实用函数。这可以在任何 numpy/scipy 或 Python 函数或类上调用,尽管编译的内置函数不会显示任何内容。
scipy 和 numpy API 文档还有一个 [source]
链接,可将您带到源文件。
我认为 np.source 相对较新,但作为一个长期的 ipython
用户,我已经通过它的 ??
魔力获得了相同的信息。
np.source(np.source)
给我
def source(object, output=sys.stdout):
"""
...
"""
# Local import to speed up numpy's import time.
import inspect
try:
print("In file: %s\n" % inspect.getsourcefile(object), file=output)
print(inspect.getsource(object), file=output)
except:
print("Not available for this object.", file=output)
In [425]: np.source??
显示相同的内容,但带有一些颜色编码。
关于python - 这个 SciPy 教程指的是什么 python 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44836250/