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.
We use the getsource() method of inspect module to get the source code of the function. Returns 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.
Python – clone() function in wand libraryclone() function makes an exact copy of the original image. One can use this clone image to manipulate without affecting the original image. clone() is one of the most important function because it helps in safe manipulation of image.
The source for python 2.7 itself can be found at http://hg.python.org/cpython. Other versions of python have had their source imported onto Launchpad. You can see them here. Click on one you want to see and you can then click "Browse the Code".
inspect.getsource
It looks getsource can't get lambda's source code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With