program path

Peter Hansen peter at engcorp.com
Mon Jun 9 04:57:03 CEST 2003


Steven Taschuk wrote:
> 
> Quoth Peter Hansen:
>   [...]
> > See Mike's reply... it works fine.
> 
> Good to know.
> 
> > So basically os.path.abspath(sys.argv[0]) should be the idiomatic
> > way to find the full path where the __main__ script lives.
> 
> I notice the alternative
>     sys.modules['__main__'].__file__
> which I like because it generalizes easily to arbitrary modules,
> as the sys.argv[0] approach does not.  Does this alternative have
> any disadvantages I'm not seeing?

Not available pre-2.3, as far as I know.  Fails under 2.2 anyway.

-Peter




More information about the Python-list mailing list