Pyhton Interpreter Startup time

Aahz aahz at pythoncraft.com
Thu Aug 12 14:17:33 EDT 2004


In article <Pine.LNX.4.44.0408121103110.4649-100000 at ccc8.wpi.edu>,
Christopher T King  <squirrel at WPI.EDU> wrote:
>
>2) Pre-compile the script.  Normally, Python generates .pyc files for
>imported modules so it doesn't have to re-parse the source code, but it
>won't do this for a script specified on the command line.  You can force
>it to compile your script by importing the script in the interactive
>interpreter, but this will also run your script (possibly not desirable).  
>You can compile the script without running it by using the py_compile
>module:
>
>python -c 'import py_compile; py_compile.compile("my_script.py")'
>
>You can then run the compiled version using 'python my_script.pyc' 
>('python my_script.py' will ignore the compiled version).

That's a Bad Idea.  Better Idea: move the code into a separate module
and put the code into a function.  Then change this script into a very
short driver that imports/calls the function.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"To me vi is Zen.  To use vi is to practice zen.  Every command is a
koan.  Profound to the user, unintelligible to the uninitiated.  You
discover truth everytime you use it."  --reddy at lion.austin.ibm.com



More information about the Python-list mailing list