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?
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.
If you're trying to get the source of the currently-running module:
thismodule = sys.modules[__name__]
inspect.getsource(thismodule)