[Tutor] Re: Baffled: why doesn't range work?
Christopher Smith
csmith@blakeschool.org
Thu, 26 Jul 2001 22:10:47 -0500
Sheila King <sheila@thinkspot.net> wrote:
|
| OK, here I think I know what I'm doing...? Done enough Python now that
| I feel pretty competent.
|
<cut>
| Now, something is very wrong. The matrix A should look like this:
|
| 0.2 0.2 0.2 0.2 0.2
| 0.2 0.2 0.2 0.2 0.2
|
<cut>
That's exactly what I saw when I cut and pasted your code
into my interpreter. :-) *Except*, I didn't save this
class and load it like a module. But I have been working on
some class material myself and ran into this sort of problem
and found help from the following FAQ entry:
http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.008.htp
4.8. When I have imported a module, then edit it,
and import it again (into the same Python process),
the changes don't seem to take place. What is going on?
For reasons of efficiency as well as consistency, Python only reads
the module file on the first time a module is imported. (Otherwise
a program consisting of many modules, each of which imports the
same basic module, would read the basic module over and over again.)
To force rereading of a changed module, do this:
import modname
reload(modname)
Warning: this technique is not 100% fool-proof. In particular,
modules containing statements like
from modname import some_objects
will continue to work with the old version of the imported objects.
----
So try the reload() command after your import command...and, of course,
be sure that the version that is being loaded is the one that you have
been modifying. (I had an alias pointing to my module on a different
disk and couldn't figure out why my modifications--even with the reload--
weren't working.
/c