22

Possible Duplicate:
Why do people write #!/usr/bin/env python on the first line of a Python script?
What does the line “#!/bin/sh” mean in a UNIX shell script?

It's a comment and should be ignored by the interpreter. Why is #!/usr/bin/python still in almost every program?

asked Mar 28, 2012 at 4:00
2
  • 5
    It's more than a comment, it's a shebang. Commented Mar 28, 2012 at 4:04
  • 1
    yes it is definitely a duplicate of that Commented Mar 28, 2012 at 4:20

3 Answers 3

25

If the script is made executable, the operating system will use that first line to know which interpreter to run to parse the rest of the file to perform some action.

If you always run these kinds of scripts from the command line like python foo.py then you could remove the first line.

answered Mar 28, 2012 at 4:13
Sign up to request clarification or add additional context in comments.

1 Comment

That applies only to Unix-like operating systems. Windows, for example, doesn't do this; it typically uses the .py suffix to determine how to execute the script.
4

Not actually. It is tradition in Unix like operating systems to use the interpreter path given in the first line and use the path to that interpreter for interpreting the rest of the program. It is called as Shebang line. You would not cared for it if you were not on Unix like systems (linux. Mac OS, FreeBSD etc) but there are attempts in Python community to use similar shebang lines on windows too.

answered Mar 28, 2012 at 4:18

Comments

1

Read the Wikipedia article Shebang. Also remember outside the *nix world, the first shebang prefixed line is considered as a comment.

answered Mar 28, 2012 at 4:33

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.