[Tutor] compiled Python Files ?? [print / .pyc and import] (fwd)

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Mon, 10 Dec 2001 11:34:45 -0800 (PST)


Hi Frank,

Let me send your respond to the list, so that the others there can respond
as well.  Talk to you later!

---------- Forwarded message ----------
Date: Mon, 10 Dec 2001 09:39:43 -0800
From: Frank Peavy <fpeavy@pop.net>
To: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] compiled Python Files ?? [print / .pyc and import]


> > I have one more FX.py file that contains:
> >
> > import F1.py
> > import F2.py
>
>Hmmm... did this work?  Your FX.py file might need:
>
>###
>import F1
>import F2
>###

Yes, you were correct, my FX.py file contains only:
import F1
import F2

 >However, perhaps we don't want 'print' to skip lines.  If we put a
>trailing comma on a print statement, 'print' will put a space instead:

Thanks for the "heads up" on this one. Always nice to get additional 
information.

>It's because your FX.py program imported the other two 'modules' --- doing
>an import has this effect.  Let's talk about this below.

So, if I understand you correctly. If I have one file that imports other 
"modules", the modules get compiled but the calling file doesn't. This 
seems a little strange to me, but that is how it is, that is how it is.

Perhaps this is where all the OO stuff comes into play, eh?
In my opinion, it implies that most applications should be written in 
"modules" and imported by a single, short .py file. Is this correct?  It 
would seem to me that that would give you imported compiled modules that 
execute the quickest.

> > I understand I can run the .pyc files, instead of the .py files. Is
> > this true?
>
>Yes, it's true.  However, I wouldn't recommend deleting the .py files,
>sine the .pyc files are very unreadable.  *grin*
If I run my F1.pyc file with the following command:

python F1.pyc

I get:

hello
run_pyc_file: nested_scopes: 0

What does this mean? If running a .py is the same as running a .pyc, then 
shouldn't I get the same results?

> > Why didn't I get a FX.pyc file also... ? The first two files compiled but
> > the third file that imported the other two didn't.
>
>Ah!  But if we had a third program that did something like:
>
>###
>import FX
>###
>
>Python will make an FX.pyc file for us.

So, as my comments above about OO, there should be a single small file that 
calls all the other modules, correct?