1

I've loaded a couple of functions (f and g) from another script in my jupyter notebook. if I pass the parameters, I am able to get the proper output. My question is, is it possible for me to see the whole definition of the function (f or g)?

I tried to see the function but it shows the memory location that was assigned to it.

Prabhat
  • 61
  • 7
  • Possible duplicate of [How can I get the source code of a Python function?](https://stackoverflow.com/questions/427453/how-can-i-get-the-source-code-of-a-python-function) – bruno desthuilliers Jul 08 '19 at 10:46

2 Answers2

1

You need to comment your function inside (check docstring, https://www.python.org/dev/peps/pep-0257/) like

def func(a,b):
    """
        Wonderful
    """
    return a+b

Then in your jupyter notebook you can use Shift + Tab on your function.

I can not comment, but this comes from another thread How can I see function arguments in IPython Notebook Server 3?

PauZen
  • 102
  • 4
1

You can do this with the built in inspect library.

The below snippet should get you acquainted with how to see the source code of a function.

def hello_world():
   print("hello_world")

import inspect
source = inspect.getsource(hello_world)
print(source)