Assuming you have a python file like so
#python #comment x = raw_input() exec(x)
How could you get the source of the entire file, including the comments with exec?
This is exactly what the inspect module is there for. See the Retrieving source code section in particular.
inspect
If you're trying to get the source of the currently-running module:
thismodule = sys.modules[__name__] inspect.getsource(thismodule)
1.4m articles
1.4m replys
5 comments
56.9k users