.pyc files

Newt newt_e at blueyonder.co.uk
Tue Jan 28 17:39:35 EST 2003


"Peter Hansen" <peter at engcorp.com> wrote in message
news:3E368D1A.FF61316A at engcorp.com...
> Carl Banks wrote:
> >
> > Peter Hansen wrote:
> > > Newt wrote:
> > >>
> > >> From a command line, how do I create pyc files? I know I can do it
from
> > >> within IDLE, but I want to use a different editor (for other
languages).
> > >
> > > I just started wondering, why do you want to do this?  Do you
> > > realize that Python automatically creates the pyc files for
> > > you when you import modules?  It is only in rare cases that
> > > you actually need to generate a .pyc file "manually".  Maybe
> > > this is not such a case?  Just wondering...
> >
> > Maybe he's trying to install a package by hand.  If you just copy the
> > .py files to a library directory, a user python process couldn't store
> > the .pyc files, so you compile the .py files before copying.
>
> I got the impression from the "I want to use a different editor" part
> that he thinks he needs to compile Python code from within the editor
> before running it during development, just as you often do in an IDE
> for a statically compiled language such as C.  Maybe your theory is
> closer to the truth though.
>
> -Peter

As suggested, I want to compile from within IDE so that my .pyc file gets
updated.
Perhaps there is an alternative approach though.
Is it possible to force an import to reproduce the .pyc file? e.g. if I have
a file newt_i.py, which is imported by newt.py, then
when I first run it newt_i.pyc get 'compiled' to newt_i.pyc. If I then
change newt_i.py, and run newt.py, then it will still import the existing
newt_i.pyc, not a .pyc version of the new file. Is this correct?

Would reload(newt_i) (within the relevent code) do the trick?

Newt






More information about the Python-list mailing list