473,385 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
2 1973
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
18
by: JKop | last post by:
Here's what I know so far: You have a C++ project. You have source files in it. When you go to compile it, first thing the preprocessor sticks the header files into each source file. So now...
16
by: matthurne | last post by:
I just started learning C++ on my own...I'm using Accelerated C++. Something it hasn't explained and I keep wondering about is how header files actually work. I suspect it doesn't get into it...
5
by: dave.harper | last post by:
I started learning C++ a few days ago, and I've run into a couple questions regarding what is included in the executable when the source is compiled... I've written a simple, 1-D rocket predicting...
9
by: Charley Kyd | last post by:
I'm a newbie who needs advice about how to use external files of JavaScript code. I spent an hour this afternoon browsing through JavaScript books at the local book store. In about 15 different...
3
by: pooja | last post by:
Suppose i have created a class c1 with f1()in c1.cpp and included this c1.cpp in file1.cpp file , which is also having main() by giving the statement #include "c1.cpp". the same i can do by...
2
by: Glen | last post by:
As I understand it, when the first page of an application is accessed, all ASPX/ASCX/etc. files in the same folder are compiled using the JIT compiler. Is there a way to turn this feature off? ...
0
by: Joergen Bech | last post by:
Fairly new to ASP.NET 1.1. Getting the error below when running application on a web server outside of my control, but only the first time I run it: 1. After a long period of inactivity (or...
1
by: dorandoran | last post by:
I created an MSI package and it works great. However, the source code aren't compiled. They show up row in the test web server. This is No No in our environment. Are there any steps that I am missing...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.