A Google Csoportok már nem támogatja az új Usenet-bejegyzéseket és -feliratkozásokat. A korábbi tartalmak továbbra is megtekinthetők.

find a .py path

0 megtekintés
Ugrás az első olvasatlan üzenetre

hg

olvasatlan,
2007. jan. 5. 4:09:002007. 01. 05.
Hi,

Is there an easy way for a script being executed (from anywhere) to know
where is is ... something in os.path ?

Thanks,

hg

hg

olvasatlan,
2007. jan. 5. 4:11:492007. 01. 05.
hg wrote:

oops: os.path.abspath(sys.argv[0])

hg

Laszlo Nagy

olvasatlan,
2007. jan. 5. 11:16:082007. 01. 05.
– hg, pytho...@python.org
hg i'rta:

> Hi,
>
> Is there an easy way for a script being executed (from anywhere) to know
> where is is ... something in os.path ?
>
__file__

You can also use os.argv[0] but that is not the same...

Laszlo

hg

olvasatlan,
2007. jan. 5. 4:29:242007. 01. 05.
Laszlo Nagy wrote:

Thanks

Laszlo Nagy

olvasatlan,
2007. jan. 5. 11:33:092007. 01. 05.
– hg, pytho...@python.org
hg írta:
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!

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

laurent rahuel

olvasatlan,
2007. jan. 5. 16:25:202007. 01. 05.
Hi,

What about :

import os.path
print os.path.abspath(__file__)

hg a écrit :

Gabriel Genellina

olvasatlan,
2007. jan. 7. 14:07:562007. 01. 07.
On 5 ene, 13:33, Laszlo Nagy <gand...@designaproduct.biz> wrote:

> 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

0 új üzenet