pyc file [Newbie Question]
editor at musicwords.net
Tue Apr 3 08:44:41 CEST 2007
Just starting to learn Python and going through the Tutorial in the Help
file. FWIW, I'm a hobbyist programmer -- not extremely knowledgeable, but
not entirely clueless.
In 6.1.2 of the Tutorial, I find this: "The modification time of the version
of spam.py used to create spam.pyc is recorded in spam.pyc, and the .pyc
file is ignored if these don't match." Either I don't understand this, or it
Working through the tutorial, I created a file called fibo.py in my text
editor, and imported it into Idle. It worked as expected. I then edited the
file and resaved it. I used del fibo, followed by import fibo.
My edits are not accessible in Idle. Python seems still to be importing the
earlier version of fibo.pyc, even though the modification time of fibo.py is
now different. (I'm in Windows XP, if that makes a difference.)
I consistently get the error message "AttributeError: 'module' object has no
attribute 'xyz'", even though I've just defined a new function xyz in
fibo.py and saved the file, then deleted and reimported.
One point of possible confusion here is in the line in the following
paragraph of 6.1.2, "Whenever spam.py is successfully compiled...." My
question is, is it compiled when being imported? I didn't spot any mention
in the Tutorial of when or how a .py file might be (or would automatically
be) compiled, so I'm assuming that it's automatically compiled while being
imported. If this is a bad assumption, then maybe it's the root of my
misunderstanding. Maybe I have to _do_ something to fibo.py in order to
create a new version of fibo.pyc.
Sorry to be so long-winded, but I want to be precise about this. Can anyone
clarify for me what's happening here? Thanks!
More information about the Python-list