Best Class for Persistent, Ordered List
I want the semantics of python lists with persistence; in particular, I want to be sure that if I put objects in the list I will later get them out in the same order. I have been using PersistentList, borrowed from somewhere, that is basically a regular list with a little persistence machinery tickling added. I notice that there are BTree classes and related set classes, in particular OOSet. Does anyone know if that preserves order? From the name and the test suite it looks as if it doesn't, even though it has sequence semantics. I've looked at the c source only enough to see the answer is not immediately obvious there! So will OOSet do what I want? If not, is something else appropriate? Thanks.
OOSet preserves order. Here's a trick that will come in handy when you want to test this kind of thing: - cd to your Zope's lib/python directory - invoke python (the version that you compiled Zope with) - at the interactive prompt type "import Zope" All the magic that happens at startup happens when you "import Zope", so at that point you can try things interactively. We'll do OOSet as an example: $ python Python 2.2 (#1, May 12 2002, 22:12:18) [GCC 2.95.3-5 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information.
import Zope from BTrees.OOBTree import OOSet set = OOSet() set.insert(1) 1 set.insert(2) 1 set.insert(10) 1 set.insert(5) 1 set OOSet([1, 2, 5, 10]) set.keys() [1, 2, 5, 10]
See the Interfaces.py file in the BTrees package for BTrees documentation. HTH, - C ----- Original Message ----- From: "Ross Boylan" <RossBoylan@stanfordalumni.org> To: <zope@zope.org> Cc: "Ross Boylan" <RossBoylan@stanfordalumni.org> Sent: Sunday, July 28, 2002 1:02 AM Subject: [Zope] Best Class for Persistent, Ordered List
I want the semantics of python lists with persistence; in particular, I want to be sure that if I put objects in the list I will later get them out in the same order.
I have been using PersistentList, borrowed from somewhere, that is basically a regular list with a little persistence machinery tickling added.
I notice that there are BTree classes and related set classes, in particular OOSet. Does anyone know if that preserves order? From the name and the test suite it looks as if it doesn't, even though it has sequence semantics. I've looked at the c source only enough to see the answer is not immediately obvious there!
So will OOSet do what I want? If not, is something else appropriate?
Thanks.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Chris McDonough <chrism@zope.com> wrote:
OOSet preserves order.
[...]
set = OOSet() set.insert(1) 1 set.insert(2) 1 set.insert(10) 1 set.insert(5) 1 set OOSet([1, 2, 5, 10]) set.keys() [1, 2, 5, 10]
Well, I would say that this conclusively proves that OOSet *does not* preserve order :-) Besides, given the name (set), I didn't expect it to. Florent -- Florent Guillaume, Nuxeo (Paris, France) +33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com
Whoops, yes. What I meant to say was that it keeps its elements in sorted order.
Well, I would say that this conclusively proves that OOSet *does not* preserve order :-)
Besides, given the name (set), I didn't expect it to.
Wait a second, I just reread Ross' original question. He *doesn't* want the items to be sorted. I misunderstood, sorry! There's nothing wrong with PersistentList or just a plain old Python list for this purpose. Order of insertion is preserved in either. ----- Original Message ----- From: "Chris McDonough" <chrism@zope.com> To: "Florent Guillaume" <fg@nuxeo.com> Cc: <zope@zope.org> Sent: Sunday, July 28, 2002 12:37 PM Subject: Re: [Zope] Best Class for Persistent, Ordered List
Whoops, yes. What I meant to say was that it keeps its elements in sorted order.
Well, I would say that this conclusively proves that OOSet *does not* preserve order :-)
Besides, given the name (set), I didn't expect it to.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
At 03:30 PM 7/28/02 -0400, Chris McDonough wrote:
Wait a second, I just reread Ross' original question. He *doesn't* want the items to be sorted. I misunderstood, sorry!
There's nothing wrong with PersistentList or just a plain old Python list for this purpose. Order of insertion is preserved in either.
I'm glad someone was paying attention! Thanks, Florent. Is PersistentList available anywhere in the Zope core? As far as I could tell, it's not, so I've stuck my own file in with it. Also, I thought perhaps there might be some performance or concurrency issues with vanilla (Persistent or not) lists. P.S. Just out of curiosity, how are the OOSet elements ordered? via __cmp__?
At 03:30 PM 7/28/02 -0400, Chris McDonough wrote:
Wait a second, I just reread Ross' original question. He *doesn't* want the items to be sorted. I misunderstood, sorry!
There's nothing wrong with PersistentList or just a plain old Python list for this purpose. Order of insertion is preserved in either.
I'm glad someone was paying attention! Thanks, Florent.
What did you say? ;-)
Is PersistentList available anywhere in the Zope core? As far as I
could
tell, it's not, so I've stuck my own file in with it.
No, it doesn't come in the Zope core.
Also, I thought perhaps there might be some performance or concurrency issues with vanilla (Persistent or not) lists.
No. ZODB handles the concurrency issues. If you change the same object in more than one thread at the same time, a conflict error is raised and Zope tries again.
P.S. Just out of curiosity, how are the OOSet elements ordered? via __cmp__?
I'm not sure, but that would make sense. - C
- cd to your Zope's lib/python directory - invoke python (the version that you compiled Zope with) - at the interactive prompt type "import Zope"
This has been such a useful tip. I've spent the better part of two days poking around in python console learning a lot more about python and Zope's objects than I did trying to make products with edit-refresh-traceback cycles. The mistakes I was making with with import and from import jump out at you right away. Great stuff. I would like to step it up to use Pythonwin for more experimentation, The browsing and code-complete features should make it a lot of fun. I've got Pythonwin 147 installed into my zope's python (used the registry editor to make a python2.1 entry mimicing that of python2.2, so the installer finds it). If you set the Pythonwin to startup in that dir, you can't load the IDE. I added the path c:\progra~1\zope\lib\python to the Python Path, but I can't "import Zope". I can browse those classes in the Python Path, but they interactive prompt doesn't see the \lib\python heirarchy, unless there's some special syntax to refer to it that I haven't seen yet. PythonWin's PythonPath setting C:\PROGRA~1\Zope\bin\Lib;C:\PROGRA~1\Zope\bin\DLLs; C:\PROGRA~1\Zope\lib\python
import Zope Traceback (most recent call last): File "<interactive input>", line 1, in ? ImportError: No module named Zope
Any ideas?
You may need to set the PYTHONHOME environment variable to Zope/lib/python, but make sure to also add an entry in PYTHONPATH to the "normal" Python library directory. ----- Original Message ----- From: "Jeff Kowalczyk" <jtk@yahoo.com> Newsgroups: gmane.comp.web.zope.general To: <zope@zope.org> Sent: Wednesday, July 31, 2002 11:34 AM Subject: [Zope] configuring Pythonwin for "import Zope"
- cd to your Zope's lib/python directory - invoke python (the version that you compiled Zope with) - at the interactive prompt type "import Zope"
This has been such a useful tip. I've spent the better part of two days poking around in python console learning a lot more about python and Zope's objects than I did trying to make products with edit-refresh-traceback cycles. The mistakes I was making with with import and from import jump out at you right away. Great stuff.
I would like to step it up to use Pythonwin for more experimentation, The browsing and code-complete features should make it a lot of fun. I've got Pythonwin 147 installed into my zope's python (used the registry editor to make a python2.1 entry mimicing that of python2.2, so the installer finds it). If you set the Pythonwin to startup in that dir, you can't load the IDE.
I added the path c:\progra~1\zope\lib\python to the Python Path, but I can't "import Zope". I can browse those classes in the Python Path, but they interactive prompt doesn't see the \lib\python heirarchy, unless there's some special syntax to refer to it that I haven't seen yet.
PythonWin's PythonPath setting C:\PROGRA~1\Zope\bin\Lib;C:\PROGRA~1\Zope\bin\DLLs; C:\PROGRA~1\Zope\lib\python
import Zope Traceback (most recent call last): File "<interactive input>", line 1, in ? ImportError: No module named Zope
Any ideas?
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Jeff Kowalczyk <jtk@yahoo.com> wrote:
- cd to your Zope's lib/python directory - invoke python (the version that you compiled Zope with) - at the interactive prompt type "import Zope"
This has been such a useful tip. I've spent the better part of two days poking around in python console learning a lot more about python and Zope's objects than I did trying to make products with edit-refresh-traceback cycles. The mistakes I was making with with import and from import jump out at you right away. Great stuff.
Even better, you can do import Zope root = Zope.app() print root.objectIds() f = root.myfolder print f.objectIds() # etc. get_transaction().commit() # to save your changes if you made some. Florent -- Florent Guillaume, Nuxeo (Paris, France) +33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com
participants (4)
-
Chris McDonough -
Florent Guillaume -
Jeff Kowalczyk -
Ross Boylan