[newbie] Overwriting class definitions
Daniel Fackrell
dfackrell at DELETETHIS.linuxmail.org
Fri Jun 21 12:41:10 EDT 2002
Mike,
You'll need to reload(circle), as import will simply reuse a version that
has already been loaded.
--
Daniel Fackrell (dfackrell at linuxmail.org)
When we attempt the impossible, we can experience true growth.
"Mike Christie" <mike.christie at athensgroup.com> wrote in message
news:3D13563D.AB80D324 at athensgroup.com...
> I'm a complete newcomer to Python; I'm teaching myself Python and this is
just
> about the only Python code I've ever typed in, so my apologies for posting
a
> dumb beginner question. Here's my problem.
>
> I tried a slight variation on the Circle class example from "The Quick
Python
> Book" by Harms and McDonald. I figured I'd put the class definitions in
> script files so I could edit and reload them quickly, rather than
retyping. I
> entered this in a file called circle.py:
>
> class Circle:
> def __init__(self):
> print "Hello, version 1"
>
> Then I did this:
>
> import circle
> circle.Circle()
>
> and got
>
> Hello, version 1
>
> as expected. Then I edited the file to say "version 2" and saved it, and
then
> typed in the import statement and circle.Circle() statement again. It
says
> version 1 again.
>
> So what's happening? I assumed that when I imported the file again, it
would
> read in the class definition again and overwrite the old definition. But
that
> doesn't appear to be happening. When I exit Pythonwin and reenter, it
runs
> just fine.
>
> Do I need to destroy the existing class def first?
>
> Mike
More information about the Python-list
mailing list