February 17th, 2005, 10:36 PM
Starting with Python can't run script
Hi, I have just started fiddling around with Python. I have been able to run some sample programs with a .py extension that I found on the web but I have been unable to run anything I did myself.
I tried creating a simple python .py file that contained only :
and another one :
someList = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eight', 'ninth']
But both programs fail on either instruction giving me a syntax error. Is there something I must do like import some mandatory file or start my program with some mandatory string or something else ?
February 17th, 2005, 10:53 PM
Ok I found out I must put : #! /usr/bin/python
at the start of my script... but what if the user running it has a different path or is on windows. I can't expect everyone to modify this first line to their path before they run to program ?
February 17th, 2005, 11:19 PM
#! /usr/bin/env python
February 18th, 2005, 12:02 AM
not on windows
You dont have to put that line on windows machine .
There is somethig wrong with aglinement of you statements that all.
February 18th, 2005, 09:58 AM
I am on a Linux box.
Originally Posted by wx_uab
Since I don't have to put in this line on Windows I assume that scripts will work on Windows regardless of the path on the first line .
As for other unix box what if someone downloads the script, runs it and Python is on another path on their machine, it would be silly if they had to change the path for their own path of every Python script they download.
February 18th, 2005, 10:43 AM
In general we default to using "/usr/bin/env python" in the shebang, like Simon suggested.
This means that on systems that have the env utility, the the first version of python located on your PATH variable is used to execute the program. And, since on Microsoft's Window this line is seen as a comment you are free to leave it as is .
Another alternative of course would be to write a small script to replace the first line in these files with the specified shebang for you.
Hope this helps,
February 18th, 2005, 11:10 AM
Yes it does, thanks a lot !
Originally Posted by netytan