This is a basic tutorial on getting direct info and help of python modules from within a Jupyter notebook. Some of this tutorial is specific to Linux (particularly the commands that start with "!").
Let's get help on Python's built-in abs function:
In [6]:
help(abs)
We have to import the numpy module in order to get help on any of its functions which we attempt below. But if we ask for help on all of np (numpy), it blocks it due to simply too much output for the browser to handle. Besides, we won't be able to read it all in one sitting. So see the Help menu in the notebook web page for numpy which today points to: https://docs.scipy.org/doc/numpy/reference/
In [14]:
import numpy as np
help(np)
but we can execute commands from the Linux shell like this:
In [15]:
!echo this is output from the echo command from the Linux shell
In [16]:
!python --version
In [18]:
!python -c 'print("foo"); print("bar")'
We can count the number of lines of output of whatever command we want. Here it is the simple one-liner of python that is generating two lines of output:
In [19]:
!python -c 'print("foo"); print("bar")' | wc -l
And here is why we got the IOPub data rate exceeded error above! There is a lot of output from the help on the np module, and we do not want to see it all, anyhow.
In [2]:
!python -c 'import numpy as np; help(np)' | wc -l
But we can explore some of it by using basic Linux shell commands:
In [4]:
!python -c 'import numpy as np; help(np)' | head -20
We can ignore the big traceback from python. All it is telling us that it failed to write to the stdout, because the head command is closing its side of the pipe after 20 lines of output received.
That is nothing to worry about, but if we cared, we could just use 2>/dev/null to send all of the error (on stderr!) to the bit bucket to hide it (which normally, we should not do because it would hide errors we do need to pay attention to, but not in this peculiar case):
In [5]:
!python -c 'import numpy as np; help(np)' 2>/dev/null | head -20
If we know what function within the particular module from online resources such as https://docs.scipy.org/doc/numpy/reference/) we are interested in, we can directly get help on it within the Jupyter notebook. But we do need to import the module before asking for it, as otherwise we will see an error:
In [6]:
import numpy as np
help(np.linspace)
Likewise, we can get help on scipi module functions:
In [15]:
import numpy as np
import matplotlib as mpl
from scipy import linalg, optimize
# I don't know what difference there is between np.info and just Python's built-in help:
# np.info(optimize.fmin)
help(optimize.fmin)
It seems that the np.info function is close to the same as the builtin help function:
In [14]:
help(np.info)
In [24]:
help(np.lookfor)
In [16]:
np.lookfor('root')