#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Posts
    20
    Rep Power
    0

    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 :
    print("a")

    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 ?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Posts
    20
    Rep Power
    0
    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 ?
  4. #3
  5. (retired)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2003
    Location
    The Laboratory
    Posts
    10,101
    Rep Power
    0
    #! /usr/bin/env python

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Location
    Bimingham,AL
    Posts
    68
    Rep Power
    10

    not on windows


    You dont have to put that line on windows machine .
    There is somethig wrong with aglinement of you statements that all.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Posts
    20
    Rep Power
    0
    Originally Posted by wx_uab
    You dont have to put that line on windows machine .
    There is somethig wrong with aglinement of you statements that all.
    I am on a Linux box.

    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.
  10. #6
  11. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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,

    Mark.
    programming language development: www.netytan.com Hula

  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Posts
    20
    Rep Power
    0
    Originally Posted by netytan
    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,

    Mark.
    Yes it does, thanks a lot !

IMN logo majestic logo threadwatch logo seochat tools logo