On 08/10/2012 12:01 AM, 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.)
>
> This same thing also happens with Python (If the first line of the
> file has #!/usr/bin/env python then even if the extension is .txt, if
> you make it an executable then terminal will process it with python
> interpreter.)
>
> So far we know two things:
> 1. "#" makes the line a comment in Python.
> 2. If processing file with bash, no matter what the file extension is,
> if the first line of that file hsa "#!/usr/bin/env python" and it is
> an executable and you run it doing like ./filename.ext, the bash will
> call python interpreter to process that file.
>
> 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.
>
> My Question:
> Is it true that doing that is as same as doing #!/usr/bin/env python
> on Unix? Because I think that the matter of shebang is limited to Bash
> and Windows don't have a bash, it has a Command Prompt. And I don't
> think such thing happens in Windows.
Nothing to do with Windows, or bash really.  It's a question of who
interprets the line you're typing, and then how that program decides
which program to run.  Unix-like systems have one set of conventions,
but there's no problem breaking them if you don't mind upsetting users.

Windows has a different convention, and there's no problem there in
breaking it.  The standard shell for Windows NT systems is called
cmd.exe (It was command.com for MSDOS).  But many other shells have been
written for Windows, both free and commercial.  It's likely that at
least one of them processes the shebang line according to Unix
conventions.  Perhaps your book has available such an alternative shell.

Cygwin can be installed into Windows.  I would expect that Cygwin comes
with its own shell.  However, once you're using that one, you probably
don't use filenames with colons inside them.  I haven't used Windows
much in the last few years, but seems to me Cygwin mapped the C: drive
into some place like  /mnt/c_drive  If I have it even close, then the
shebang line would look something like:

    #!/mnt/c_drive/Python32/python.exe


-- 

DaveA

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to