very simple python script question
I am completely new to programming and Linux.
I want to know how to run a script (.py) I've written At the top of the script I have entered #!/usr/bin/python In a shell I have cd'd to the directory the script is sitting in. Typed in "python" to invoke the interpretor then typed "python linux_python_test.py" tried "./ linux_python_test.py" and "linux_python.py" HAve also tried removing the .py extention and tried those three again. All the while the same error message crops up.... File "<stdin>", line 1 python linux_python_test.py ^ What am I doing wrong? |
I think you should be able to run the script by simple cd'ing to the directory where the program is and giving command
python script.py Just to be safe make it executable. |
Thanks LL,
I'm afraid that didn't work. by the way I changed directory before going into the Python Interpreter. S Quote:
|
#!<path> on the first line tells the shell to use a specific interpreter when executing the script. The file must then have the execute bit set: "chmod 775 script.py"
Not specifying it requires you to call the interpreter with the file as an argument (i.e. python script.py) Try removing the #!... on the first line and simply executing the script as an option to the interpreter: "python script.py" If you really want to keep the #!, then make sure the path you're specifying is the true path to the interpreter: "which python" will help you with that. |
Quote:
(Of course you could do it from the interpreter as well but you'd need to write code). So simply go back to your normal Linux command line, cd into the directory where the script is and type 'python scriptname' where script name is the name of the file. |
Have you done that has been suggested to you in earlier posts?
chmod +x script.py |
Quote:
Thank you for all the replies. This is what I was doing wrong. I was trying to invoke the script though the Python Interpreter |
All times are GMT -5. The time now is 04:34 AM. |