[ZODB-Dev] simple newbie BTrees.Length question

Chris McDonough chrism at plope.com
Mon Jan 19 10:12:32 EST 2004


Hi,

I think you want:

class Counter:
  def __init__(self):
    self.count=Length()
  def storeCount(self, c):
    self.count.set(c)
  def getCount(self):
    return self.count()

Otherwise you will replace the Length object with (presumably) an
integer in storeCount and you will return the Length object instead of
an integer in getCount.  A good example of using a Length object is
present in the Catalog.py module in Zope's ZCatalog product.

On Mon, 2004-01-19 at 09:39, Bakhtiar A Hamid wrote:
> hi
> in my journey to understand zope product coding, i intend to use 
> BTrees.Length to store some objects.  after googling, there's little info 
> about BTrees, apart from ajung's wiki and some links to this list.
> 
> i'm interested in BTrees.Length so that i can get the automatic conflict 
> resolution for my products.  say i have these:
> 
> Type "copyright", "credits" or "license" for more information.
> >>> from BTrees.Length import Length
> >>> class Counter:
> ...   def __init__(self):
> ...     self.count=Length()
> ...   def storeCount(self, c):
> ...     self.count=c
> ...   def getCount(self):
> ...     return self.count
> ...
> >>> x=Counter()
> >>> x.storeCount(1)
> >>> x.getCount()
> 1
> >>> x.storeCount(2)
> >>> x.getCount()
> 2
> >>> x.storeCount([1,2,3,4])
> >>> x.getCount()
> [1, 2, 3, 4]
> 
> it is true that Counter class has conflict resolution, since self.count is 
> a BTrees.Length  
> 
> when i storeCount, do i just do it that way and zodb will 
> do the rest?  should i care?  what happens if i store a list?  and change 
> the list again?
> 
> i'm sorry if these questions are inappropriate.
> 
> thanks
> trying-to-understand-btrees
> 
> 
> 
> _______________________________________________
> For more information about ZODB, see the ZODB Wiki:
> http://www.zope.org/Wikis/ZODB/
> 
> ZODB-Dev mailing list  -  ZODB-Dev at zope.org
> http://mail.zope.org/mailman/listinfo/zodb-dev




More information about the ZODB-Dev mailing list