[Tutor] starting python within script

Tim Condit timc@ans.net
Tue, 29 Aug 2000 13:59:13 -0400 (EDT)


On Tue, 29 Aug 2000, Remco Gerlich wrote:

> On Tue, Aug 29, 2000 at 11:15:11AM -0400, Tim Condit wrote:
> > I'm curious about the two ways I see python started from inside scripts.
> > These are the locations on my desktop computer at work: 
> > 
> > #!/usr/bin/env python
> > #!/usr/local/bin/python
> > 
> > One of these creates a .pyc byte compiled file. The other doesn't. What is
> > the advantage of one over the other?
> 
> /usr/local/bin/ is a hardcoded path, it may not work everywhere; sometimes
> Python is in /usr/bin, sometimes in /usr/local/bin, then in /opt/python,
> etc. 
> 
> "env" is a program that starts another program, it looks "python" up in
> PATH and starts it. So that env line finds Python wherever it is, if it's
> in your PATH.
> 
> So "env" works on more computers, but it can't be used if Python isn't in
> the path (like on some web servers). Env is always in /usr/bin/env.
> 
> I think the rule is "use /usr/bin/env python, if you can."
> 

okay. 

> But the thing about creating .pyc files is weird. When I try it, neither
> produces a .pyc files. Those should never be created when the Python file
> is run from the command line, but only when the script is imported from
> another script (I don't know why that is). Are you sure that is what
> happens?
> 

No, I'm not. I thought that's what was happening, but after some
experimenting, found that you were right - the file was only created when
I import a file in the form of a module. Sorry about the confusion, and
thanks for the info. 

> -- 
> Remco Gerlich,  scarblac@pino.selwerd.nl
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor
> 

Tim Condit
UUNet Network Quality Services
734-214-7548
tcondit@uu.net