sys.argv[0] - Returns path and filename.

Paul Moore gustav at morpheus.demon.co.uk
Thu Jun 27 09:29:08 EDT 2002


"Mark McEahern" <marklists at mceahern.com> writes:

>> How do I get the current path of the script I am running, on the mac
>> osx and the linux box ? (Any work around would be great, I don't want
>> to have to hardcode the path into the script, or even give the path as
>> an argument,I want the script to know where it is.)
>
> import os
> print os.getcwd()

Or os.path.abspath(sys.argv[0]).

Run this before you change directory...

Paul.




More information about the Python-list mailing list