By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,772 Members | 919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,772 IT Pros & Developers. It's quick & easy.

Pickling new-style classes w/ getinitargs

P: n/a
What is the correct way to pickle a new-style class that makes use of
__getinitargs__? In the test below, __getinitargs__ gets called only on
old-style classes (pickle appears to call __getinitargs__ only if the object
type is InstanceType, but new-style class instances have a type of the the
class). Google didn't turn up anything obvious; I'm starting my search on
SourceForge but it's extremely slow at the moment.

Thanks for any pointers,
The test:

from pickle import dumps

class A(object):
def __init__(self, i):
self.i = i

def __getinitargs__(self):
print 'newstyle getinitargs!'
return (self.i,)

class B:
def __init__(self, i):
self.i = i

def __getinitargs__(self):
print 'oldstyle getinitargs!'
return (self.i,)

Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.