Reputation:
SciPy's website has a tutorial that references a python function source
that lists the source code of functions written in python, but I cannot use it in python or find documentation for it online. The reference is at the bottom of this page. I see that the inspect
module has similar functions but I'm still curious as to what function in what module they are referring to.
Upvotes: 1
Views: 45
Reputation: 231385
np.source
is a utility function in numpy
. This can be called on any numpy/scipy or Python function or class, though compiled built-ins won't show anything.
The scipy and numpy API docs also have a [source]
link that takes you to a source file.
I think np.source is relatively new, but as a long time ipython
user I've been getting the same information with its ??
magic.
np.source(np.source)
gives me
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??
shows the same thing but with some color coding.
Upvotes: 1