johnroth1 at gmail
Aug 21, 2012, 1:35 PM
Post #28 of 28
On Sunday, August 19, 2012 7:57:46 PM UTC-6, kj wrote:
Re: Why doesn't Python remember the initial directory?
[In reply to]
> 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.