python inspect.getsource 1

python inspect.getsource

inspect.getsource(object)

Return the text of the source code for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a single string. An OSError is raised if the source code cannot be retrieved.

Here is what the above code is Doing:
1. We import the inspect module.
2. We define a function called get_source_code.
3. We use the inspect.getsource function to get the source code of the function passed to the get_source_code function.
4. We return the source code.
5. We call the get_source_code function and pass it the add function.
6. We print the source code.

Similar Posts