# Python: Running a program - Should be simple

1. Dec 29, 2012

Hello

As strange thing is happening. I have created a simple file using emacs (on a Mac) that contains the following:

Code (Text):
def main():

print "hello!!!"

if __name__ == "__main__":
main()

And I have saved it in the working directory as hello.py

In a terminal window, if I type
Code (Text):
python hello.py
it works great. Now I set the execute bit using
Code (Text):
chmod +x hello.py
and when I try to run it using ./hello.py I get syntax errors?!

Code (Text):
./hello.py: line 1: syntax error near unexpected token ('
./hello.py: line 1: def main():'

Any ideas on this? Thanks!

2. Dec 29, 2012

### Staff: Mentor

Perhaps without #!/usr/bin/python it is treated as a bash script? Just guessing.

3. Dec 29, 2012

Borek! Thanks! That what exactly it! I am not too good at terminal or Python. I saw the #!/usr/bin/python in the example file and I thought it was a comment

4. Dec 29, 2012

### Hurkyl

Staff Emeritus
It is a python comment. I think it would even be a shell script comment if it were anywhere but the first line.

But your shell treats the first line specially if it starts with #!, and interprets it as a path to something to execute to interpret the script.

This is why scripting languages all use # to start comments: so that this convention your shell uses can be used without confusing your scripting language.