How to get path of a .py script

Grant Edwards grante at visi.com
Wed Dec 11 16:12:10 EST 2002


In article <b2f253f2.0212110415.4368239c at posting.google.com>, Devrim Erdem wrote:

> On linux I have a script runSomething.py, the script is
> sometimes executed from a link on the desktop or from another
> dir.
> 
> How can I get the path of the script file itself so that I can
> locate files which are relative to the script file ?

Locating required files based on the location of the executable
is generally considered a bad thing to do in the Unix world,
and doing so will annoy users who don't expect that sort of
behavior.

The Unix philosophy is that the location of files should be
determined by

 1) Standard locations such as
     /etc/<something>
     /opt/<something>
     /usr/local/lib/<something>
     $HOME/<something>
     ./

    "The nice thing abour standards is that there are so many
    from which to choose."

 2) Paths specified in config files found in standard locations
 
 3) Environment variables
 
 4) Command line options

You are, of course, free to locate files based on sys.argv[0],
as long as you are aware that you're doing "A Bad Thing".

-- 
Grant Edwards                   grante             Yow!  My LIBRARY CARD
                                  at               expired...
                               visi.com            



More information about the Python-list mailing list