script portability trick 
Author Message
 script portability trick

A traditional unix trick in Tcl/Tk is to start scripts like this:

#!/bin/sh
# the next line starts wish \

This causes the Bourne shell to search the user's executable path to
find wish each time the script is executed. Because the script doesn't
depend on wish being in a particular directory, it is more portable
(sh is almost always in /bin, but wish can be anywhere).

Is there a similar trick for Python? Thanks.



Tue, 06 Jul 2004 04:03:19 GMT  
 script portability trick

Quote:

>A traditional unix trick in Tcl/Tk is to start scripts like this:

>#!/bin/sh
># the next line starts wish \

>This causes the Bourne shell to search the user's executable path to
>find wish each time the script is executed. Because the script doesn't
>depend on wish being in a particular directory, it is more portable
>(sh is almost always in /bin, but wish can be anywhere).

>Is there a similar trick for Python? Thanks.

The standard gimmick for python is:

#!/usr/bin/env python
--

Hugs and backrubs -- I break Rule 6                 http://www.*-*-*.com/
Androgynous poly {*filter*} vanilla {*filter*} het Pythonista  

"There are times when effort is important and necessary, but this should
not be taken as any kind of m{*filter*}imperative."  --jdecker



Tue, 06 Jul 2004 04:24:07 GMT  
 script portability trick

Quote:

> A traditional unix trick in Tcl/Tk is to start scripts like this:

> #!/bin/sh
> # the next line starts wish \

> This causes the Bourne shell to search the user's executable path to
> find wish each time the script is executed. Because the script doesn't
> depend on wish being in a particular directory, it is more portable
> (sh is almost always in /bin, but wish can be anywhere).

> Is there a similar trick for Python? Thanks.

I usually start my python scripts with

#!/usr/bin/env python

I haven't seen an environment where env wasn't in /usr/bin yet.

Anyone?

r.



Tue, 06 Jul 2004 04:27:53 GMT  
 script portability trick

Quote:
> A traditional unix trick in Tcl/Tk is to start scripts like this:

> #!/bin/sh
> # the next line starts wish \

> This causes the Bourne shell to search the user's executable path to
> find wish each time the script is executed. Because the script doesn't
> depend on wish being in a particular directory, it is more portable
> (sh is almost always in /bin, but wish can be anywhere).

> Is there a similar trick for Python? Thanks.

"How do I make a Python script executable":

    http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.063.htp

regards
 Steve
--
Consulting, training, speaking: http://www.holdenweb.com/
Python Web Programming: http://pydish.holdenweb.com/pwp/



Tue, 06 Jul 2004 04:32:31 GMT  
 script portability trick
Quote:



>>A traditional unix trick in Tcl/Tk is to start scripts like this:

>>#!/bin/sh
>># the next line starts wish \

>>This causes the Bourne shell to search the user's executable path to
>>find wish each time the script is executed. Because the script doesn't
>>depend on wish being in a particular directory, it is more portable
>>(sh is almost always in /bin, but wish can be anywhere).

>>Is there a similar trick for Python? Thanks.

>The standard gimmick for Python is:

>#!/usr/bin/env python

                        .
                        .
                        .
Neither of these are particularly "about" wish or Python;
they're just ancient Unix traditions that Tclers and
Pythoneers happen to have differentially adopted.  The same
"tricks" or "gimmicks" work for either equally well, though.

Incidentally, the first one is suboptimal, as <URL:
http://mini.net/tcl/812.html > documents.
--


Business:  http://www.Phaseit.net
Personal:  http://starbase.neosoft.com/~claird/home.html



Tue, 06 Jul 2004 05:00:58 GMT  
 script portability trick

Quote:

> I usually start my python scripts with

> #!/usr/bin/env python

> I haven't seen an environment where env wasn't in /usr/bin yet.

> Anyone?

If you install Python manually, it will invariably be in /usr/local/bin.

The /usr/bin/env trick is fairly good practice, but runs into a problem
if there are multiple Python's (named python) installed on the same
system.  For instance, if your default installation puts one in
/usr/bin, and you upgrade to a new version and it gets installed in
/usr/local/bin.  Now which one /usr/bin/env finds will depend on the
PATH setting, which, for instance, will tend to be different in an
interactive shell than in a cron job.  (The best approach is to rename
or delete the python in /usr/bin if you really don't want that one.)

Using #!/usr/local/bin/python isn't too bad, since you can always put a
symlink in /usr/local/bin to where the Python executable really is
should it not be there.

--

 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Laws are silent in time of war.
\__/ Cicero
    Esperanto reference / http://www.alcyone.com/max/lang/esperanto/
 An Esperanto reference for English speakers.



Tue, 06 Jul 2004 05:03:22 GMT  
 script portability trick

Quote:
> If you install Python manually, it will invariably be in /usr/local/bin.

This is false.

If you install Python, it will be wherever you put it.

/usr/local/bin is the default, but no more.  Many people have machines
with Python manually installed in locations other than there.

-Justin



Tue, 06 Jul 2004 13:46:39 GMT  
 script portability trick

Quote:
>I haven't seen an environment where env wasn't in /usr/bin yet.

Apparently BeOS is one such platform. It doesn't have a /usr at all,
so env is /bin/env. Given Palm's recent behaviour towards BeOS, I'm
not sure it matters, though.

Cheers,

Duncan.

--
 -- Duncan Grisby  \  Research Engineer  --
  -- AT&T Laboratories Cambridge          --
   -- http://www.uk.research.att.com/~dpg1 --



Tue, 06 Jul 2004 18:20:54 GMT  
 script portability trick

Quote:


> >I haven't seen an environment where env wasn't in /usr/bin yet.

> Apparently BeOS is one such platform. It doesn't have a /usr at all,
> so env is /bin/env.

that's what symbolic links are for.

--
Garry Hodgson                   Let my inspiration flow
Senior Hacker                      in token rhyme suggesting rhythm
Software Innovation Services    that will not forsake me
AT&T Labs                          'til my tale is told and done.



Tue, 06 Jul 2004 23:32:19 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Script SFNode Syntax Trick -- Dot Drilling Legal?

2. Neat scripting trick...

3. Neat Net Tricks

4. Programming tricks,etc

5. A Neat ALC Trick

6. Fun trick summing letters

7. Fun trick summing letters but?

8. More pet ALC tricks...

9. awk -F trick

10. Performance tricks on Visual Smalltalk

11. any wiki works 5i3 setup tricks?`

12. 18 Search Engine Tricks

 

 
Powered by phpBB® Forum Software