[Zope] Newbie questions about OOBTree, persistence

Lennart Regebro lennart@regebro.nu
Fri, 25 Apr 2003 18:11:36 +0200


Glen Ecklund wrote:
> ===============================================================
> 
>     from BTrees.OOBTree import OOBTree
> 
>     tree = OOBTree()
>     tree['a'] = 'AAA'
> 
> Gets:
> 
>     Error Type: TypeError
>     Error Value: object does not support item or slice assignment

Not sure why that doesn't work, actually. OIBTrees sure allow you to use 
tree['a'] syntax, so so should OOBTrees, and I don't see why you 
shouldnt be able to assign 'AAA' to it.

Hang on....<testing>...the above code works for me, so maybe there is 
some weirdness in accessing these from a Python script? I don't see why 
though. Maybe you need to specially admit access to __getitem__?
I'm no good at the Python script security...

>     tree.insert['a'] = 'AAA'

Insert is a method, not a dictionary.

>     insert(tree, 'a', 'AAA')
Well:
>     Error Value: global name 'insert' is not defined
Explains that very well.

>     from BTrees.OOBTree import OOBTree
> 
>     tree = OOBTree()
>     OOBTree.insert(tree, 'a', 'AAA')

Insert is not a class method, but an object method, you should call it 
on the object.

> Do I use
>     Val = tree['a']
> to retrieve the value?

Yes.

> Third, how do I make my object persistent?

The Zope BTrees are persistent, you only need to assign the BTree to an 
attribute and you are done.