Python+ubuntu error
Question: Am trying to run the following python program

    
    
    import re
    regex=re.compile("http...imgs.xkcd.com.comics.[\\S]*.[jpg|png]")
    f=open('out.txt')
    for a in f:
        print regex.findall(a)
        print '\n'
    

when I type the code into the interpreter manually, it works as expected but
when i save it as a file and try to run it , it gives errors. The command i
used to run it is

    
    
    chmod +x 
    sudo ./pymod.py
    

ERROR: ./pymod.py: 2: Syntax error: "(" unexpected

if i dont use sudo, the error i get is

    
    
    ./pymod.py: line 2: syntax error near unexpected token `('
    ./pymod.py: line 2: `regex=re.compile("http...imgs.xkcd.com.comics.[\\S]*.[jpg|png]")'
    

am using ubuntu 10.04 with everything on default

it takes about 10-15 seconds for the error to appear


Answer: Your file should start with shebang. You should include the path to the python
interpreter

    
    
    #!/usr/bin/env python
    import re
    regex=re.compile("http...imgs.xkcd.com.comics.[\\S]*.[jpg|png]")
    

Check out : <http://en.wikipedia.org/wiki/Shebang_(Unix>)

