get script path

Rob Wolfe rw at smsnet.pl
Mon Dec 4 07:52:21 EST 2006


hg wrote:
> Hi,
>
> must I parse argv[0] to get it, or is there an easier way (that works under
> Windows and *nix)?
>
> Ex:
>
> python /home/hg/test/test.py ==> test.py #knows it is in /home/hg/test

IMHO it is easy enough:

>>> dname, fname = os.path.split("/home/hg/test/test.py")
>>> dname
'/home/hg/test'

-- 
HTH,
Rob




More information about the Python-list mailing list