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

Blake Winton bwinton@tor.dhs.org
Thu, 29 Mar 2001 10:39:16 -0500


* D-Man <dsh8290@rit.edu> [010329 10:29]:
> On Thu, Mar 29, 2001 at 12:30:07PM +0100, Karim Yaici wrote:
> |    >python foo.py x y z
> |    Is there anyway I can make it work without calling Python i.e
> |    >foo.py x y z
> On Windows your choices are (1) to make an exe, (2) make the program a
> wrapper (ie .bat file) that runs the interpreter on the real script,
> or (3) not use the command line.  
> For choice number 3 you need to set the default action.  Open
> _windows_ (not internet) explorer, click on view->options then click
> the "File Types" tab.  Find .py files and specify (through the
> dialogs, ask if you want more details) that it should be run by the
> interpreter.  Then when you double click on it in explorer it will run
> in the interpreter.  No effect on the command line though.  Of course,
> you can't pass commandline arguments using this method (ie sys.argv).

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
instructions for choice #3, you should be able to, at the command
line, type "foo.py x y z", and it will work.  As an added bonus,
you might be able to edit your "PATHEXT" variable, and set it to
something like ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PY"
So that you can then just type in "foo x y z", and it will still
work.  (I'm not sure whether that's only an NT thing, or if the
other versions of Windows do the same thing.)

> #!/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
at least have a way for me to only type it in once, instead of
in _every_ file...

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

Later,
Blake.
-- 
9:40pm up 52 days, 21:07, 2 users, load average: 0.02, 0.09, 0.07