Finding startup files
Bernhard Herzog
bh at intevation.de
Thu May 12 12:59:43 EDT 2005
Grant Edwards <grante at visi.com> writes:
> On 2005-05-11, jeff elkins <jeffelkins at earthlink.net> wrote:
>
>> I'm totally new to Python (obvious,yes?) so how might argv[0] fail?
>
> argv[0] contains whatever is put there by the program that
> exec'ed you, and can therefore contain just about anything (or
> nothing). It may not contain a full path, and your program's
> install directory may not be in your $PATH (it be executed by a
> shortcut or symlink).
That's true for the C-level, i.e. main's argv. If you're only concerned
about CPython and the program is a script living in a file, then
sys.argv[0] is the filename the python interpreter itself used to read
the script. Hence it's a valid filename that refers to the script. It
may be a relative filename, of course, in which case it won't be correct
anymore if the program changes its working directory.
Bernhard
--
Intevation GmbH http://intevation.de/
Skencil http://skencil.org/
Thuban http://thuban.intevation.org/
More information about the Python-list
mailing list