[newbie] Overwriting class definitions

Sean 'Shaleh' Perry shalehperry at attbi.com
Fri Jun 21 12:51:20 EDT 2002


On 21-Jun-2002 Mike Christie wrote:
> 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.
> 

tutor at python.org exists exactly to answer new to python (and to programming)
questions.

> 
> 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.
> 

if you do:

import foo
import foo
import foo

only the first import happens.  python does a check, sees it has done the
work and ignores the rest.  This is what happened to you.

I find that existing the interpreter is the safest thing to do while doing
interative coding like this.





More information about the Python-list mailing list