executing python programs as if they were on OS path (noob)

Peter Hansen peter at engcorp.com
Tue Aug 3 21:30:03 CEST 2004


Darren Dale wrote:
> Is there a place to put python programs so I dont have to refer to the 
> absolute path everytime I want to call them? For example:
> 
> if I am in /home/me and want to execute:
> 
> python /home/me/python/export.py temp.dat
> 
> what could I do so this will work:
> 
> python export.py temp.dat

At least two options (assuming you're on Linux... you
didn't specify your OS unfortunately):

1. Make the scripts executable (+x with chmod), make sure
the folder they are in *is* in the OS path, and put in the
following as the first line of the scripts:

     #!/usr/bin/env python

2. Make your own shell script which knows where to look for your
Python files and execute that instead of "python".  Call it "mypy"
or something to make sure you don't mess up anything else in the
system which wants the normal behaviour with "python".

Note that with your example above, you don't have to use the full
absolute path, as just "python python/export.py temp.dat" would
work.

-Peter



More information about the Python-list mailing list