Generic constructors and duplication of internal Python logic

Michele Simionato michele.simionato at poste.it
Thu Apr 29 09:17:45 EDT 2004


sdementen at hotmail.com (Sebastien de Menten) wrote in message news:<8dad5312.0404282313.8eb76b0 at posting.google.com>...
> 2) I don't get the point about the .pyc

inspect.getsource look at the .py file; in some situations (i.e. trying to
obfuscate code) you may want to ship the .pyc file only; so inspect.getsource
cannot work (unless you decompile the .pyc file and restore .py).

For instance try

$ cat example.py
import inspect,sys

print inspect.getsource(sys.modules["__main__" ])

run it and  then remove example.py.

Also, the approach breaks down if the code is executed dynamically;
for instance C-c C-c in emacs would not work.


   Michele Simionato



More information about the Python-list mailing list