<div class="question-status question-originals-of-duplicate">
This question already has an answer here:
Python reflection - Can I use this to get the source code of a method definition
I've got a system in which I constantly experiment with the contents of a function, after which I run the program. Since I often have many terminal windows open, I sometimes don't exactly know which version of the function belongs to which terminal window.
Is there a way to print the source code of a specific function to the terminal?
Alright. Thanks to Hoopdady who provided a similar question here on Stackoverflow. Just to give the solution for future readers. I needed to use the inspect module, and using its method "getsource" I can simply print the source of a method or function to the command line.
import inspect import mymodule print inspect.getsource(mymodule.sayHello)