[Tutor] .pyc files and executables?

Lance E Sloan lsloan@umich.edu
Wed, 15 Aug 2001 14:11:42 -0400


I'm using Python 2.0 on a UNIX machine (Solaris 2.6) to write some
CGIs.  I'm trying to find out more about .pyc files, because I think
it may improve performance at least a little if I can get my CGIs
saved as .pyc files.

My Python CGIs start out with a line like this:

  #!/usr/local/python/bin/python

I notice that .pyc files are not created for my main programs whether
or not they have a .py extension.  However, .pyc files are created
for modules (all have .py extensions) that my programs import.

Now, I've run Python interactively and created .pyc files for my
main programs using the statement, "import myprogram.py".  Now I have
myprogram.pyc.  It's not executable by itself, but I can run it if
I use the command, "python myprogram.pyc".

What I want to know is this:  If I run myprogram.py, which starts up
the interpreter, will Python see myprogram.pyc there and use it
instead of reparsing the code in myprogram.py?

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"