[Tutor] python from shell

Guillermo Fernandez guillermo.fernandez@epfl.ch
Tue, 09 Jul 2002 10:57:40 +0930


> is there a way I could start my python appz from command line just like other normall apps
> ex. vim => and vim starts
Yes

> where should I place my .py file ?
In your path. Your path is the variable PATH. Try the command "echo
$PATH" in your terminal. That's the directories where your shell is
going to look for the program you started.

You can also put it in a directory of your choice and add this directory
to your path, but it's easier to directly put it in a directory already
existing in your path variable.

> what changes do I have to make in my .py file or somewhere else ?
You have to add #! and the path of your python command in the first line
of your code. In my case is:
#! /usr/bin/python

You can even get rid of the .py extension!

Than you have to make the file executable (chmod 755 file.py) and put
these file in one of your directories of your path.
Typically, I put my files in /usr/local/bin/

Exacmple:
>> cat > example
#! /usr/bin/python
print "Hello world"
^C
>> cat example
#! /usr/bin/python
print "Hello world"
>> ls -l example
-rw-r--r--    1 guille      users        8843 jui  9 10:55 example
>> chmod 755 example
>> ls -l example
-rwxr-xr-x    1 guille      users        8843 jui  9 10:55 example
>> mv example /usr/local/bin/
>> example
Hello world
>>

Guille