RE: [Zope] Help with ZODB Howto?
-----Original Message----- From: Sean Holdsworth [mailto:sh@onyx.net] Sent: Tuesday, November 23, 1999 1:12 PM To: zope@zope.org Subject: [Zope] Help with ZODB Howto?
Hi All!
Firstly I want to reproduce the functionality of a simple database that I have written in Python using the shelve module. To this end I've read up on ZODB and looked at the existing Howto. For experimenting, using the file storage method is fine. I'm assuming that I can test the code in the Howto running it outside of the Zope environment as standalone Python (after correcting the closing bracket typo and adding some wrapper code of course). Unfortunately this fails miserably
How does it fail 'miserably'? Others have had success with the How-To, although I admit it could use some editorial polish. -Michel
On 23-Nov-99 Michel Pelletier wrote:
-----Original Message----- From: Sean Holdsworth [mailto:sh@onyx.net] Sent: Tuesday, November 23, 1999 1:12 PM To: zope@zope.org Subject: [Zope] Help with ZODB Howto?
Hi All!
Firstly I want to reproduce the functionality of a simple database that I have written in Python using the shelve module. To this end I've read up on ZODB and looked at the existing Howto. For experimenting, using the file storage method is fine. I'm assuming that I can test the code in the Howto running it outside of the Zope environment as standalone Python (after correcting the closing bracket typo and adding some wrapper code of course). Unfortunately this fails miserably
How does it fail 'miserably'? Others have had success with the How-To, although I admit it could use some editorial polish.
Firstly, apologies if my post implied criticism of the Howto itself; the vast majority of the Zope howtos that I have looked at, including the one for ZODP, have provided me with very useful information. I was referring to my own failure in getting the example code running or even understanding properly why it was failing. To provide some details, I simply hacked out the example code from the howto and added a line to create an instance of the MySimpleZODBApp class as follows: import Persistence import ZODB class Person(Persistence.Persistent): """A Persistent Person""" def __init__(self, name, age): self.name = name self.age = age class MySimpleZODBApp: """ A simple application object that manages persistent object's of the 'Person' class. """ def __init__(self, file='Data.fs'): """ Create a database, connect to it and get the root object out of it. """ self.db = ZODB.DB(ZODB.FileStorage(file)) self.connection = self.db.open() self.root = self.connection.root() if not len(root): self.root['billy'] = Person('Billy', 77) # normally Zope will handle transactions, # but in this special case, we need to # commit the transaction to save the new # persistent object get_transaction().commit() def addPerson(self, name, age): """ Adds a 'Person' to the database """ if self.root.has_key(name): raise 'PersonAllReadyExists', "They're allready there" else: self.root[name] = Person(name, age) get_transaction().commit() def delPerson(self, name): """ Deletes a 'Person' from the database """ if self.root.has_key(name): del self.root[name] get_transaction().commit() else: raise 'NoSuchPerson', 'Who?' if __name__ == '__main__': db = MySimpleZODBApp() If I run this with the python interpreter that came with the Zope 2.0.1 binary distribution for Linux x86 I get a traceback as follows: Traceback (innermost last): File "howto.py", line 50, in ? db = MySimpleZODBApp() File "howto.py", line 19, in __init__ self.db = ZODB.DB(ZODB.FileStorage(file)) AttributeError: FileStorage Part of my original question was whether this behavior is a result of interfaces changing between when the howto was written and as they are in 2.0.1? I know little of how Zope has evolved and so just wanted to check if this could be the case or if there is something else I'm not understanding. Thanks, Sean Sean Holdsworth | Work: sh@onyx.net | Zetland Buildings Senior Network Engineer | Home: sh@hob.cx | Exchange Square Onyx Internet Ltd. | Tel: +44 (0)1642 216200 | Middlesbrough http://www.onyx.net | Fax: +44 (0)1642 216201 | TS1 1DE
participants (2)
-
Michel Pelletier -
Sean Holdsworth