[newbie] Overwriting class definitions

Mike Christie mike.christie at athensgroup.com
Fri Jun 21 12:37:18 EDT 2002


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