Is there an easy way for a script being executed (from anywhere) to know
where is is ... something in os.path ?
Thanks,
hg
oops: os.path.abspath(sys.argv[0])
hg
You can also use os.argv[0] but that is not the same...
Laszlo
Thanks
/usr/bin/python prog.py
and
./prog.py
In the first case, sys.argv[0] will be /usr/bin/python!
You should better use
os.path.abspath(__file__)
(that will work for normal python programs, but not for py2exe compiled
programs or for modules imported from a zip file...)
Best,
Laszlo
What about :
import os.path
print os.path.abspath(__file__)
hg a écrit :
> Be aware with this. It is different when you do
>
> /usr/bin/python prog.py
>
> and
>
> ./prog.py
>
> In the first case, sys.argv[0] will be /usr/bin/python!
No, sys.argv[0] is always the running script, and sys.argv[1] the first
argument after the script, and so on. It doesn't matter if you call
python implicitely, or with other options. Try this:
/usr/bin/python -i -u -O prog.py
--
Gabriel Genellina