By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,676 Members | 2,262 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,676 IT Pros & Developers. It's quick & easy.

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

P: n/a
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 myapp.py

the file which contains the class definition (class.py), is compiled
to a .PYC file, but the application (myapp.py) is not.

Why is the application file not compiled to .PYC ?

thanks
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Tony C wrote:

Why is the application file not compiled to .PYC ?


When you import a .py file, a .pyc is created. When you run it
directly, it isn't. The thinking is probably that something that's a
module is less likely to change than something that's a script. I don't
really think there's much stock to take in the difference; it's just the
way it is.

--
__ Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ Love is when you wake up in the morning and have a big smile.
-- Anggun
Jul 18 '05 #2

P: n/a
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 myapp.py

the file which contains the class definition (class.py), is compiled
to a .PYC file, but the application (myapp.py) 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.

Rob
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.