Matt Barnicle a écrit :
>>>On Dec 1, 4:47 pm, Matt Barnicle <[EMAIL PROTECTED]> wrote:
>>
>>aye yaye aye...  thanks for the pointers in the right direction..  i
>>fiddled around with the code for a while and now i've reduced it to the
>>*real* issue...  i have a class dict variable that apparently holds its
>>value across instantiations of new objects..

If it's a class attribute, it's indeed shared between all instances...

>>  the problem can be
>>illustrated in the following much simpler code:
>>
>>>>>class foo():
>>
>>...     bar = { 'baz': 'bing' }
(snip)
> ok, i see...  python has a concept i'm not accustomed to which i found
> described here:
> 
> http://zephyrfalcon.org/labs/python_pitfalls.html
> 4. Class attributes vs instance attributes
> 
> so i'm sure what is going on is obvious to experienced python
> programmers...  i'm not really sure how to get around this though.  

It's not a problem:

class Foo(object):
   def __init__(self):
     self.bar = {'baz':'bing'}



>i'll
> need to spend some time on reworking our models code i guess...  i
> inherited this from someone, and what he was trying to do was to set
> default values for objects representing tables (in kind of a simple ORM
> layer) and storing the values in a dict, and when the object is
> instantiated, the table is queried and the default dict values are
> overwritten. 

class Foo(object):
   bar = {'baz':'bing'}
   def __init__(self):
     self.bar = self.bar
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to