[Tutor] How to run a script file
John Purser
johnp at milwaukielumber.com
Wed Jan 5 00:04:12 CET 2005
Bernard,
If you're new to Linux you might not be aware of an additional method to run
python scripts. If the first line of your script is:
#!/usr/bin/python
And you've set your script permissions to be executable (chmod 700
myscript.py) then you can run your script just like any other program. You
can double click on it in a GUI environment or run it from a command prompt
by just typing the script name. Or depending on the value of $PATH variable
you might need to type "./myscript.py". Those first characters have to be
right though. I'm assuming your python is in /usr/bin. And that is a hash
mark followed by an exclamation point. This is called "hash bang" in
uningo.
John Purser
-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On Behalf
Of Patric Michael
Sent: Tuesday, January 04, 2005 14:56
To: tutor at python.org
Subject: Re: [Tutor] How to run a script file
Hi Bernard...
The most basic form is to type "python" followed by the script you want
to run. If your script is not in the system path, you'll either need to cd
to
the directory, or give a full pathname: (the pythonpath doesn't come into
play until the interperter is running.
python /usr/local/share/filename.py
Remember that the script will inherit whatever permissions you currently
have, so either log in or su to the user that's expected to run the script.
Oh, and in case python itself isnt in your system path, (it probably is)
you can find it by typing "which python" at the shell prompt.
Patric
> Hi,
>
> Sorry if I missed something obvious, but how do I execute a python
> script file in the interpreter? I have "Using the Python Interpreter"
> in the Python tutorial but not much is said...
>
> (this might be a lame quesiton but so far I always used either the
> PythonWin interpreter wich has the Import function, or I ran Python
> code in an application. Now I'm on Linux so I have to learn the hard
> way!)
>
>
> Thanks
> Bernard
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist - Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list