pure aesthetic question

Michael P. Soulier msoulier at storm.ca._nospam
Sun May 25 22:42:55 EDT 2003


On Sun, 18 May 2003 18:52:11 +0200, Helmut Jarausch <jarausch at skynet.be> wrote:
> Hi
> 
> as far as I know I have to put a Python script
> into a file with suffix '.py' (e.g. BackUp.py)
> and if it gets compiled there is a BackUp.pyc or
> BackUp.pyo file.
> Is it possible (under Linux) to get the plain name
> BackUp
> which executes the compiled and/or optimized script
> when invoked by the shell (system)

You don't need to put a python script in a file ending in .py at all.
You do need to do that if you're going to import it as a library.

If you want to compile your code, and run the compiled version, the main
issue is telling the OS to use the python interpreter on that file. The
easiest way to do this is with a wrapper script. 

[msoulier at tigger msoulier]$ cat foo.py
#!/usr/bin/python

print 'foo'
[msoulier at tigger msoulier]$ python -c \
   'import py_compile; py_compile.compile("'foo.py'")'
[msoulier at tigger msoulier]$ rm foo.py
[msoulier at tigger msoulier]$ python foo.pyc
foo

So, it works just fine. You just need to wrapper it now in a
bourne-shell script. 

[msoulier at tigger msoulier]$ cat foo
#!/bin/sh

/usr/bin/python $HOME/foo.pyc
[msoulier at tigger msoulier]$ ./foo
foo

That's it. 

Mike

-- 
Michael P. Soulier <msoulier at digitaltorque.ca>, GnuPG pub key: 5BC8BE08
"...the word HACK is used as a verb to indicate a massive amount
of nerd-like effort."  -Harley Hahn, A Student's Guide to Unix
HTML Email Considered Harmful: http://expita.com/nomime.html




More information about the Python-list mailing list