In the event that the function is from a source document accessible on the filesystem, at that point inspect.getsource(foo) may be of help:
If foo is defined as:
def foo(arg1,arg2):
#do something with args
a = arg1 + arg2
return a
then:
import inspect
lines = inspect.getsource(foo)
print(lines)
It returns:
def foo(arg1,arg2):
#do something with args
a = arg1 + arg2
return a
In any case, I accept that if the function is gathered from a string, stream, or imported from an incorporated document, at that point you can't recover its source code.
Are you pretty much interested to learn python in detail? Come and join the python training course to gain more knowledge.
To know more about this you can have a look at the following video tutorial:-