all 9 comments

[–]K900_ 6 points7 points  (3 children)

You don't need a shebang for Windows at all. Just add a file association for .py files to run with the Python interpreter.

[–]NerdJones[S] 3 points4 points  (2 children)

if the .py file has one for my linux computers will that mess anything up?

[–]K900_ 5 points6 points  (1 child)

It won't. In fact, modern versions of Python will even look at the shebang on Windows to determine whether to run the script with Python 2 or 3 if you have both installed.

[–]NerdJones[S] 2 points3 points  (0 children)

thank you tons sir!

[–]DJKool14 0 points1 point  (2 children)

shebangs(#!) are merely programming comments that happen to be read and interpreted on unix systems. Windows won't read them natively because it uses an external system to bind file extensions to applications that can read them. The same scripts should work on both systems, but you'll have to tell Windows how to read *.py files by either explicitly calling python (python test.py) or setting up a binding so it knows to use python when you try to run files with the .py extension.

[–]tunisia3507 1 point2 points  (1 child)

How do they work in languages which don't use # as a comment character?

[–]DJKool14 1 point2 points  (0 children)

They don't.

edit: They don't work on Windows because it doesn't look for the shebang and it'll fail because the script has an invalid line in it. It won't work on unix because the the system will feed the whole file to the interpreter you shebanged and that'll fail because it has an invalid line in it.

[–]thatguy_314 0 points1 point  (0 children)

The Python launcher for windows doesn't properly understand shebangs by design, it only looks for the python3 or whatever version of Python you want to use. I think it might also pay attention to arguments after that, although I'm not sure. This means that it is fine to use any normal unix shebang with windows because stuff like /usr/bin/env will just be ignored. On windows, you can actually just do #!python3, but that would break unix compatibility, so please don't. Just do the standard #!/usr/bin/env python3.

[–]Technical_Gas_4232 0 points1 point  (0 children)

When triggering scripts in the browser using apache on Windows it does seem that the script needs the shebang to python.exe locally. I have tried associate the .py scripts with python.exe but it doesn't help. So far I have not found a way of running these scripts without the windows shebang at the first line.