Why doesn't Python remember the initial directory?

John Roth johnroth1 at gmail.com
Tue Aug 21 22:35:16 CEST 2012


On Sunday, August 19, 2012 7:57:46 PM UTC-6, kj wrote:

> This means that no library code can ever count on, for example,
> 
> being able to reliably find the path to the file that contains the
> 
> definition of __main__. 

If you want to find that, look up __main__ in sys.modules and then look at the __file__ attribute. You need to be a bit careful with this; the import machinery was rewritten for the upcoming 3.3 release, and there were several changes to the module information.

John Roth


More information about the Python-list mailing list