[Tutor] Confusion with Python, Bash and Command Prompt

Steven D'Aprano steve at pearwood.info
Fri Aug 10 06:20:18 CEST 2012


On 10/08/12 14:01, Santosh Kumar wrote:
> Hello There,
>
> We all know that line starting with "#" in Python is a comment.
>
> We also know that when the first line of any file (with any extension)
> has "#!/usr/bin/env bash" and if you make it executable and do
> ./filename.ext in the terminal then it will be considered as bash file
> (in this case even if the extension is.py the terminal will take it as
> bash file.)

That is not Python's doing. That is the shell, and so it depends
entirely on your choice of operating system and shell. It works on Unix,
Linux and probably Mac OS, but not on Windows.

As far as Python is concerned, "#!/usr/bin/env python" is just a
meaningless comment.


> Now let's get back. I'm reading a book "A Byte of Python"
> (http://www.swaroopch.org/notes/Python). In this page:
> http://www.swaroopch.org/notes/Python_en:First_Steps, under the
> section Using a Source File. There is a line saying that "A word of
> caution on the shebang..". On the next line the book says we can use
> #!C:\Python32\python.exe to make it executable.

The book is completely wrong there. Windows does not pay any attention
to shebang lines.

Although, soon, Python itself will provide a launcher for Windows which
understands shebang lines:

http://www.python.org/dev/peps/pep-0397/



-- 
Steven


More information about the Tutor mailing list