[Tutor] How to run a script file

John Purser johnp at milwaukielumber.com
Wed Jan 5 00:57:22 CET 2005


I'm not sure why it fails "of course".  How do you know it's failing at the
first slash?  Also you might want to look at your .profile file in your home
directory and modify your path there.

John Purser 

-----Original Message-----
From: tutor-bounces+johnp=milwaukielumber.com at python.org
[mailto:tutor-bounces+johnp=milwaukielumber.com at python.org] On Behalf Of
Bernard Lebel
Sent: Tuesday, January 04, 2005 15:33
To: tutor at python.org
Subject: Re: [Tutor] How to run a script file

Okay sorry I meant once you're in Python.

I'm in Bash console, type Python, enter the Python interpreter.

Then I add my custom path to the sys.path list (because my user 
permissions do not allow my to put anything in the Lib directory) and 
then I try an
import /home/bernardl/python/myScript.py
but of course if fails as soon the first slash is read.


Thanks
Bernard


John Purser wrote:
> 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



More information about the Tutor mailing list