Numpy 如何从IPython打开在线参考?
有没有办法让IPython打开指向相应在线参考的浏览器 特别是对于numpy、scipy、matplotlibNumpy 如何从IPython打开在线参考?,numpy,ipython,Numpy,Ipython,有没有办法让IPython打开指向相应在线参考的浏览器 特别是对于numpy、scipy、matplotlib 例如,在终端中很难读取的文档。我不认为有直接的方法可以让IPython或任何shell在线打开文档,因为shell的主要工作是让您与shell的目标交互 不过,我们可以编写一个脚本,用文档在浏览器上打开一个新选项卡。像这样: import webbrowser docsList = { "numpy" : lambda x: "https://docs.scipy.org/d
例如,在终端中很难读取的文档。我不认为有直接的方法可以让IPython或任何shell在线打开文档,因为shell的主要工作是让您与shell的目标交互 不过,我们可以编写一个脚本,用文档在浏览器上打开一个新选项卡。像这样:
import webbrowser
docsList = {
"numpy" : lambda x: "https://docs.scipy.org/doc/numpy/reference/generated/" + x + ".html",
"scipy" : lambda x: "https://docs.scipy.org/doc/scipy/reference/generated/" + x + ".html",
"matplotlib" : lambda x: "https://matplotlib.org/api/" + x.split('.')[1] + "_api.html",
"default" : lambda x: "https://www.google.com/search?q=documentation+" + x
}
def online(method_name):
"""
Opens up the documentation for method_name on the default browser.
If the package doesn't match any entry in the dictionary, falls back to
Google.
Usage
-------
>>> lookUp.online("numpy.linalg.cholesky")
>>> lookUp.online("matplotlib.contour")
"""
try:
url = make_url(method_name)
except AttributeError:
print("Enter the method name as a string and try again")
return
webbrowser.open(url, new = 2)
return
def make_url(method_name):
package_name = method_name.split('.')[0]
try:
return docsList[package_name](method_name)
except KeyError:
return docsList["default"](method_name)
您可以在Python可以找到的位置将上述内容保存为lookUp.py,然后在需要时将其导入
注意事项:
此方法将字符串作为输入,因此如果对函数调用它,它将抛出错误
>>> lookUp.online("numpy.linalg.cholesky")
会有用的
>>> lookUp.online(numpy.linalg.cholesky)
我会要求你把它作为一个字符串。
因此,请使用autocomplete访问该函数,然后用引号将其括起来以使其正常工作