Mutable class attributes are shared among all instances, is it normal ?

Chris Barker chrishbarker at home.net
Thu Jun 7 20:07:53 EDT 2001


Chris Barker wrote:
OOPS, sorry, I accidentally left some erronos stuff in my example. It
shuld be just:
> Try this:
> 
> >>> reload(cl) # it needs to be reloaded to get a clean copy of Y
> <module 'cl' from 'cl.pyc'>
> >>>
> >>> print cl.X.val
> None
> >>> x1=cl.X()
> >>> print cl.X.val # note: it hasn't changed.
> None
> 
> >>> print cl.Y.val
> [None]
> >>> y1=cl.Y()
> >>> print cl.Y.val # note it has changed
> [0.91001740255497787]

Sorry about that.

-Chris

-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------



More information about the Python-list mailing list