[wxpython-users] Static variables in wx.Python?

Christopher Barker Chris.Barker at noaa.gov
Wed May 7 17:04:20 PDT 2008


raffaello wrote:
> While strings, integers, floating 
> point objects and the like at the second or third subclassing start 
> always with the original value, lists seem to conserve the values 
> acquired in the former subclassings,

I think the key here is that ints, floats, strings are non-mutable, and 
lists are mutable.

I suspect that you are doing things like:

self.A_number = 4

Now self.Anumber is referencing a different object, and other classes, 
instances etc are still referencing the same old one)

but:

self.A_list.append(something)

Now you've altered the original list, rather than re-binding the name to 
a new object. If you do:

self.A_list = []

it should behave the same way as numbers.

> I have solved the problem, for the moment, re-declaring the list in  
> __init__, but I feel uneasy with  just an empiric solution.

That's the correct solution. If you want different instances to have 
different values for their attributes, they should be set in __init__.

-Chris




-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov


More information about the wxpython-users mailing list