<s>[INST] How can I get the source code of a Python function? Suppose I have a Python function as defined below:
def foo(arg1,arg2):
    #do something with args
    a = arg1 + arg2
    return a

I can get the name of the function using foo.func_name. How can I programmatically get its source code, as I typed above?
 [/INST] If the function is from a source file available on the filesystem, then inspect.getsourcelines(foo) might be of help.
I believe that if the function is compiled from a string, stream or imported from a compiled file, then you cannot retrieve its source code.
 </s>