35

For example, I want to check the source code of a python library, directly in the notebook, is there a way to do that?

Thank you

2 Answers 2

90

Type the fully qualified function name, then type ??.

Sign up to request clarification or add additional context in comments.

7 Comments

This is something really Cool!
@Chinny84, is there a way to configure the notebook to use an external editor? I want to use a bigger window to read the code. By default, it seems the external widow is displayed in the browser, and therefor there is no syntax coloring, which is bad.
Typing e.g. numpy.random.rand gives me the docstring! what do you mean exactly by a full qualified function name? Trying cv2.resize?? also doesn't work. Could the reason be that these function are not actually written in pure Python?
I typed this: sklearn.metrics.classification_report?? .. then what to do?
from sklearn.metrics import classification_report and then classification_report?? + Shift Enter
|
11

You can use inspect module (which is built in) - for example you can see the tree module below from scikit-learn.

import inspect
from sklearn import tree
inspect.getsourcelines(tree.tree) 

1 Comment

inspect.getsource(tree.tree) would print it like a file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.