[Tutor] How can I make my script work without calling Python?

D-Man dsh8290@rit.edu
Thu, 29 Mar 2001 11:00:22 -0500


On Thu, Mar 29, 2001 at 10:39:16AM -0500, Blake Winton wrote:
| * D-Man <dsh8290@rit.edu> [010329 10:29]:
| 
| or (4) Set up your command line to just run python files.
| 
| Choice #4 is the same as choice #3.  In fact, if you follow the

Oh, ok, that's nice.  I guess I've never tried that.  I didn't think
setting the file type in windows would affect it's dos imitation.

| > #!/usr/bin/env python
| > as the very first line of the script, then the shell will know to run
| > it using python.  (Just one example of why *nix is superior to 'doze
| > ;-))
| 
| Because I need to tell _every_ python script I write that it's
| actually a python script?  Surely if *nix is so great it could
| figure that out from the ".py" extension on my files.  ;)  Or

Of course.  Say I did this (taken from a real project, but not mine)

---- /usr/bin/pmail
#!/usr/bin/env python

...


Without the #! how would the shell know that 'pmail' is a python
program?  Should I be required to write a sh script called 'pmail'
that is nothing more than  'pmail.py $*' ?  

IMO that's a waste and an indication of shortsighted and inflexible
design.  The #! means you can mix and match any filename with any
interpreter much like python's uniform treatment of all objects.  (ie
no primitive type vs. reference (object) type like in Java, etc)

| at least have a way for me to only type it in once, instead of
| in _every_ file...

---- ~/.vimrc ----
; <most snipped>

autocmd! BufNewFile  *.py read ~/util/autoheaders/Python


---- ~/util/autoheaders/Python
#!/usr/bin/env python

# any other text (like name, license, etc) to appear automagically at
# the beginning of each new .py file <grin>


The only problem I have is that the first line (in the new buffer) is
always blank with the header beginning on the second line.  Is there a
way to fix this?

| (I'm actually a *nix bigot at heart, but I also enjoy a good
|  debate.  ;)

Following your lead ... ;-)

-D