Hello,
I'm having trouble storing to the ZODB.
The code in question reads a string argument and selects a module from the current directory that matches the string argument, importing it into the current class:
class Division(Persistence.Persistent): "A collection of rounds." def __init__(self, name, type, flags = []): self.name = name self.typename = type self.rules = __import__(type) self.rounds = [] self.teams = {} self.judges = [] self.flags = flags
(rest of class snipped in the interests of brevity)
Here's the result of a call using the arguments ('Test', 'APDA') in Python 1.5.2 and Zope 2.4.0
Traceback (innermost last): File "<stdin>", line 1, in ? File "t3s.py", line 909, in add_division get_transaction().commit() File "/usr/lib/python1.5/ZODB/Transaction.py", line 300, in commit j.commit(o,self) File "/usr/lib/python1.5/ZODB/Connection.py", line 375, in commit dump(state) cPickle.UnpickleableError: Cannot pickle <type 'module'> objects
(add_division is a function that creates the division and stores it to a global database; essentially, a wrapper.)
I tried the native cPickle module in Python 2.1.1 (to ensure that I had a clean version). Same problem -- it chokes on module objects.
The purpose of this code is to enable the user to select from several different sets of 'rules' ('APDA' is currently the only one written), which are implemented as Python modules. At run-time, when a 'division' is created, the ruleset is imported into the object instance as self
Do you have any suggestions as to how I might implement this?
Thanks,
Joe
(correction) I erroneously left this paragraph unfinished
The purpose of this code is to enable the user to select from several different sets of 'rules' ('APDA' is currently the only one written), which are implemented as Python modules. At run-time, when a 'division' is created, the ruleset is imported into the object instance as self.rules. The functions of the module can then be called as methods of the division (for example self.rules.list_flags()).
Joe
On Sun, Jul 29, 2001 at 08:20:27PM -0400, Joseph Barillari wrote:
Do you have any suggestions as to how I might implement this?
I just learned that the standard pickle module does not support pickling of modules (Oops), and I have adjusted the relevant code accordingly.
My apologies; I ought to have researched that a bit further before posting.
Thanks,
Joe
The Python pickler cannot pickle module objects. You might try the same concept, but with class objects instead.
On Sun, 29 Jul 2001 20:20:28 -0400 Joseph Barillari jbarilla@princeton.edu wrote:
Hello,
I'm having trouble storing to the ZODB.
The code in question reads a string argument and selects a module from the current directory that matches the string argument, importing it into the current class:
class Division(Persistence.Persistent): "A collection of rounds." def __init__(self, name, type, flags = []): self.name = name self.typename = type self.rules = __import__(type) self.rounds = [] self.teams = {} self.judges = [] self.flags = flags
(rest of class snipped in the interests of brevity)
Here's the result of a call using the arguments ('Test', 'APDA') in Python 1.5.2 and Zope 2.4.0
Traceback (innermost last): File "<stdin>", line 1, in ? File "t3s.py", line 909, in add_division get_transaction().commit() File "/usr/lib/python1.5/ZODB/Transaction.py", line 300, in commit j.commit(o,self) File "/usr/lib/python1.5/ZODB/Connection.py", line 375, in commit dump(state) cPickle.UnpickleableError: Cannot pickle <type 'module'> objects
(add_division is a function that creates the division and stores it to a global database; essentially, a wrapper.)
I tried the native cPickle module in Python 2.1.1 (to ensure that I had a clean version). Same problem -- it chokes on module objects.
The purpose of this code is to enable the user to select from several different sets of 'rules' ('APDA' is currently the only one written), which are implemented as Python modules. At run-time, when a 'division' is created, the ruleset is imported into the object instance as self
Do you have any suggestions as to how I might implement this?
Thanks,
Joe