Am Freitag, 30. November 2007 19:34 schrieb Yuan HOng:
> Hi,
> It seems that I can not get list attribute of an persistent object
> changed. I have the following class, which has a list as one of its
> attributes:
> class Cart(Persistent):
>     items = []
>     amount = 0

Hehe, I had the same pitfall some weeks ago...

This has nothing to do with persitence, the problem is that you are assigning 
the dictionary to the class and not to the class instance (= the object). For 
that reason, strange things will happen, e.g.:

c2 = Cart()

So, I follow this pattern:

class Cart(Persistent):
  items = None
  def __init__(self):
    self.items = []

My problem was that I was so much focussed on Persistence, that I forgot about 
this quite simple Python issue...


Best Regards,

GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7
Zope3-users mailing list

Reply via email to