Find directory name of file?

Peter Hansen peter at
Sun Jan 29 23:23:03 CET 2006

jmdeschamps at wrote:
> also the function os.cwd() 
> ;-)

I'm not sure how os.cwd() helps, but generally the solution to this 
starts with pointing out that sys.argv[0] usually contains the path to 
the main script, which is often the answer needed.

Recipes have been posted in the past which cover a wider range of 
situations, including when running as a "py2exe'd" program (i.e. 
"frozen"), as the simple solution doesn't cover all cases.

Checking the archives would probably help.


More information about the Python-list mailing list