Use /usr/bin/env python ... why?

Tim Cargile tecargile at hotmail.com
Fri Jan 10 07:27:26 EST 2003


Paul Foley <see at below.invalid> wrote in message news:<m2lm1twxby.fsf at mycroft.actrix.gen.nz>...
> On 9 Jan 2003 12:44:41 -0800, Tim Cargile wrote:
> 
> > There was a previous thread on this that referenced a python.org FAQ
> > that I thought was incomplete.  As a casual observer I would
> > like to submit the following - in the order of most to least efficient
> > and least to most flexible (perhaps):
> 
> I think you forgot to s/flexible/buggy/ :-)
> 
> Just use
> 
>    #!/bin/sh
>    """"exec ${PYTHON:-python} -t $0 "$@";" """

Yes.  Absolutely!

And here are the 'top n' reasons to use it:

n-13)  It preserves multi-word argument boundaries.
n-12)  It's use gives one an automatic 'A' in 'Kludging 101'.
n-11)  It enhances the module's documentation. 
n-10)  It's a one-liner and everyone knows they execute faster. 
n-9 )  It's well-commented, albeit a bit tersely.
n-8 )  It's OK because something like it is in the Python FAQ (says Guido).
n-7 )  It hard-codes a -t arg and tab/spaces should ALWAYS be checked.
n-6 )  It minimizes thrashing - same as '#!/usr/bin/env python' does.
n-5 )* It uses the well-documented PYTHON environment variable.
n-4 )  It uses the most modern shell (albeit probably best).
n-3 )  It:  echo "#!/usr/bin/env" | sed -e 's@#!/usr/bin/env at Kludge@g'.
n-2 )  It hides the 'Kludge' by defining the module's __doc__ string.
n-1 )  The Kludge works!.

and ... tah taaaaaah!

   n)  Guido thought it was 'Cool.' back on 11/11/97
       when Sofin Raskin proposed the similar:

            #!/bin/sh
            """:"
            exec python $0 ${1+"$@"}
            """

       to address untoward environment limit and Guido put 
       it into the FAQs to be used as what he described as
       'a measure of last resort'.

To gild the lily and to give credit where credit is due
Neil Schemenauer should be given the 'Golden Lily' award for
his suggested upgrade of:  __doc__ = """something wonderful"""
to immediate follow the above, errrr ... workaround.


Any Questions?


Tim


PS: Email gets through if 'techalert' is somewhere in Subject.




More information about the Python-list mailing list