Viewing the code of a Python function

introspection, python

Solution

inspect.getsource It looks getsource can't get lambda's source code.

Problem

Let's say I'm working in the Python shell and I'm given a function `f`. How can I access the string containing its source code? (From the shell, not by manually opening the code file.) I want this to work even for lambda functions defined inside other functions.

Original source

Related problems