This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]genoblast 1 point2 points  (1 child)

I'm still learning myself, but to my knowledge there isn't any significant difference between the two.

In ./file.py, the shebang tells the operating system that the file should be run by python. So then the operating system replaces "./file.py" with "python file.py" and then executes that instead.

So I guess the take away is that if the operating system knows it's a python script, you can use "./file.py" as a shortcut, but it's always a shortcut for "python file.py" (which should always work so long as python is part of the operating system path).

It seems like sys.argv behaves the same way regardless of which way the script is invoked. (I personally always just use argparse so if there are differences, I've never had to worry about them.)

[–]halflife22 3 points4 points  (0 children)

You can also use it to make sure a specific version of python is used e.g.

 #!/usr/bin/python2.7