xml marshal of general (but non Python standard) class

syd syd.diamond at gmail.com
Tue Mar 29 12:23:44 EST 2005


Thank you Martin.  I had not considered pickle, and I've done my
research.  However, I'm still having problems:

Your foo class (for pickle and xml dumps) works fine for me.
>>> f=Foo()
>>> f.thanksTo='Martin'
>>> f.howMany=100
>>> pickle.dumps(f)
"(i__main__\nFoo\np0\n(dp1\nS'thanksTo'\np2\nS'Martin'\np3\nsS'howMany'\np4\nI100\nsb."

But for my identifiedPeaks class (for instance), it has trouble.  This
class contains a list of "peak" classes IdentifiedPeaks.Peak...

>>> from IdentifiedPeaks import IdentifiedPeaks
>>> identifiedPeaks=IdentifiedPeaks()
>>> identifiedPeaks.read(open('input/analysisReport.txt'))
>>> pickle.dumps(identifiedPeaks)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.3/pickle.py", line 1386, in dumps
    Pickler(file, protocol, bin).dump(obj)
  File "/usr/lib/python2.3/pickle.py", line 231, in dump
    self.save(obj)
  File "/usr/lib/python2.3/pickle.py", line 338, in save
    self.save_reduce(obj=obj, *rv)
File "/usr/lib/python2.3/pickle.py", line 433, in save_reduce
    save(state)
  File "/usr/lib/python2.3/pickle.py", line 293, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/python2.3/pickle.py", line 663, in save_dict
    self._batch_setitems(obj.iteritems())
  File "/usr/lib/python2.3/pickle.py", line 677, in _batch_setitems
    save(v)
  File "/usr/lib/python2.3/pickle.py", line 293, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/python2.3/pickle.py", line 614, in save_list
    self._batch_appends(iter(obj))
  File "/usr/lib/python2.3/pickle.py", line 629, in _batch_appends
    save(x)
  File "/usr/lib/python2.3/pickle.py", line 338, in save
    self.save_reduce(obj=obj, *rv)
  File "/usr/lib/python2.3/pickle.py", line 415, in save_reduce
    save(args)
  File "/usr/lib/python2.3/pickle.py", line 293, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/python2.3/pickle.py", line 576, in save_tuple
    save(element)
  File "/usr/lib/python2.3/pickle.py", line 293, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/python2.3/pickle.py", line 760, in save_global
    raise PicklingError(
pickle.PicklingError: Can't pickle <class 'IdentifiedPeaks.Peak'>: it's
not found as IdentifiedPeaks.Peak

xml.marshal has the problem I mentioned before...

>>> xml.marshal.generic.dumps(identifiedPeaks)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.3/site-packages/_xmlplus/marshal/generic.py",
line 59, in dumps
    L = [self.PROLOGUE + self.DTD] + self.m_root(value, dict)
  File "/usr/lib/python2.3/site-packages/_xmlplus/marshal/generic.py",
line 104, in m_root
    L = ['<%s>' % name] + self._marshal(value,dict) + ['</%s>' % name]
  File "/usr/lib/python2.3/site-packages/_xmlplus/marshal/generic.py",
line 92, in _marshal
    return getattr(self, meth)(value, dict)
AttributeError: Marshaller instance has no attribute
'm_IdentifiedPeaks'

Help would be hugely appreciated.




More information about the Python-list mailing list