Re: [Tutor] How to run a script file
Thanks everyone who answered, it's sorted now :-D Bernard ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to run a script file
> 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 YOu should be able to create a personal startup script in your homedir. I've not done it but I'm sure I remember reading about it, and its pretty standard LInux practice. > then I try an > import /home/bernardl/python/myScript.py > but of course if fails as soon the first slash is read. If you've added the path to sys.path you should only need to do import myScript no .py and no path. Remember that import does NOT import a file it imports a module object (which just happens to correspond to a file with a similar name!) HTH Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to run a script file
> 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... You can import a script at the >>> prompt as you would under Pythonwin. Or you can run IDLE much as you did Pythonwin. Or you can learn emacs and run python mode in that. Personally I just open a gvim window and a terminal and edit the code in gvim and run the program in the terminal... If I need to experiment I open a third window and run the >>> prompt there. Linux is the IDE... Alan G. PS I just got my own Linux box running again 4 months after moving house! I thought I'd try a Suse distro I got with Borlands Kylix and calamity - no python! Back to Mandrake I think. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to run a script file
You might want to try IDLE. You can open your file in an editing window and run it from there. I don't know how to start IDLE on Linux though...you need to run Lib/idlelib/idle.pyw Kent Bernard Lebel wrote: 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@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to run a script file
HI Bernard... I think I see what you might mean I'm guessing your session goes something like this: >>> import sys >>> sys.path.append(' /home/bernardl/python/') >>> import /home/bernardl/python/myScript File "", line 1 import /home/bernardl/python/myScript ^ SyntaxError: invalid syntax Right? If so, its because the full pathname is no longer necessary after you've added it to the path. Just type >>>import myScript and that will bring it in. :) Let us know if we've still misunderstood... Patric > 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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On > > Behalf Of Patric Michael Sent: Tuesday, January 04, 2005 14:56 To: > > tutor@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@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
RE: [Tutor] How to run a script file
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bernard Lebel Sent: Tuesday, January 04, 2005 15:33 To: tutor@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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf > Of Patric Michael > Sent: Tuesday, January 04, 2005 14:56 > To: tutor@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@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Patric Michael Sent: Tuesday, January 04, 2005 14:56 To: tutor@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@python.org http://mail.python.org/mailman/listinfo/tutor
RE: [Tutor] How to run a script file
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Patric Michael Sent: Tuesday, January 04, 2005 14:56 To: tutor@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@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
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@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to run a script file
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@python.org http://mail.python.org/mailman/listinfo/tutor