Is it possible to 'compile' a script?

Ian Holmes ianholmes01 at lycos.com
Fri Oct 4 07:03:48 EDT 2002


"solosnake" <solosnake at solosnake._without_this_.fsnet.co.uk> wrote in message news:<anje4l$4lm$1 at news8.svr.pol.co.uk>...

> My suggestion to those responsible for
> maintaining Python is to differentiate between calling a script which is
> then parsed and compiled into bytecode and executed, and calling a function
> which will parse and create the bytecode, but return a handle to that (now
> faster) bytecode and allow it to be executed through this handle.
> 
> Thanks for all replies.
> 
> - solosnake

When you first run a script in python the text file you created gets
"compiled" into bytecode and run (as you mentioned) you will have also
noticed that a .pyc file is created which is the bytecode version of
your script.

If you run myscript.py python will run myfile.pyc if it exists hence
speeding up subsequent executions by not having to recompile into
bytecode.  If the .py file changes then obvoiusly it is recompiled.

Therefore a handle isn't required as python uses the fastest method
possible by default.

---Mike C. Fletcher wrote
Or, you can decide to use something like the Python specialising 
compiler (Psyco).
---
This is good and I recommend it.  It increases the pystone benchmark
by approx 5 times on my machine (ran on linux or win2k - celeron 500
320Mb)

There is also pyrex you may wish to consider.



More information about the Python-list mailing list