Not all .PY files are compiled to .PYC during execution

Robert M. Emmons rmemmons at
Fri Feb 13 05:28:04 CET 2004

Tony C wrote:
> After using Python for just over a year now, I've noticed something
> for the first time.
> I've written an application in one .PY file, and a class definition in
> another.PY file. (The application instantiates one instance of the
> class.)
> When I run my application as in
> python
> the file which contains the class definition (, is compiled
> to a .PYC file, but the application ( is not.
> Why is the application file not compiled to .PYC  ?
> thanks
It is generally recommended that the main program be small and they you 
you put most of your code in modules if you have a large program and 
many modules.

I don't know officially why python works this way, but perhaps it's to 
keep launching simple.

My speculation as to why it works this way is because when you create a 
python script -- you generally are creating a command or program.  You 
don't want to have to different file names for this program -- 
especially if it's in the path.  You want the file to have a single 
launch point and this has to be source if your going to keep things simple.


More information about the Python-list mailing list