program path

Peter Hansen peter at engcorp.com
Sun Jun 8 21:31:38 CEST 2003


Steven Taschuk wrote:
> 
> Quoth Gerhard Häring:
>   [...sys.argv[0] test in WinXP...]
> > C:\>tmp\x.py
> > C:\tmp\x.py
> 
> What happens if %PATH% includes c:\tmp, and you invoke it simply
> as 'x.py', from some other directory?

See Mike's reply... it works fine.

So basically os.path.abspath(sys.argv[0]) should be the idiomatic
way to find the full path where the __main__ script lives.

(I did try searching the archives for past discussions on this
but couldn't find a reference after a minute so I gave up.)

-Peter




More information about the Python-list mailing list