Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I go to a function's definition in Jupyter notebook?

How can i go to a function definition in Jupyter?

I want something like Visual studio's f12, or eclipse's and PyCharm's ctrl+click.

I find it hard to believe this does not exist, yet couldn't find it

like image 747
Gulzar Avatar asked Nov 23 '18 17:11

Gulzar


People also ask

How do you find the description of a function in Jupyter Notebook?

Jupyter Notebook can show that documentation of the function you are calling. Press Shift+Tab to view the documentation.

How do you go inside a function in a Jupyter Notebook?

The Jupyter Notebook has two ways to get help.Place the cursor inside the parenthesis of the function, hold down shift , and press tab . Or type a function name with a question mark after it.

How do I open a Docstring in Jupyter Notebook?

Shift + Tab will show you the Docstring (documentation) for the the object you have just typed in a code cell – you can keep pressing this short cut to cycle through a few modes of documentation.

How do you call a Python function in a Jupyter Notebook?

py file), or Jupyter Notebook. Remember the file that contains the function definitions and the file calling the functions must be in the same directory. To use the functions written in one file inside another file include the import line, from filename import function_name .


1 Answers

I'm not aware of such feature that will work for all kernels.

If you are using a Python kernel and have ipython installed you can use inspection functions:

  • %pdoc <object>: Print (or run through a pager if too long) the docstring for an object. If the given object is a class, it will print both the class and theconstructor docstrings.
  • %pdef <object>: Print the call signature for any callable object. If the object is a class, print the constructor information.
  • %psource <object>: Print (or run through a pager if too long) the source code for an object.
  • %pfile <object>: Show the entire source file where an object was defined via a pager, opening it at the line where the object definition begins.
  • %who/%whos: These functions give information about identifiers you have defined interactively (not things you loaded or defined in your configuration files). %who just prints a list of identifiers and %whos prints a table with some basic details about each identifier.

Typing ??word or word?? gives access to the full information, including the source code where possible. Long strings are not snipped.

Usage Example

In [4]: pd.DataFrame?

In [5]: pd.DataFrame??

In [6]: %pdef pd.Dataframe
Object `pd.Dataframe` not found.

In [7]: %pdef pd.DataFrame
Class constructor information:
 pd.DataFrame(data=None, index=None, columns=None, dtype=None, copy=False)

In [8]: %pdoc pd.DataFrame

In [9]: %pfile pd.DataFrame

Resources

Dynamic object information

like image 109
Kamil Niski Avatar answered Oct 21 '22 03:10

Kamil Niski