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

Problem pickling exceptions in Python 2.5/2.6

P: n/a

I'm having troubles pickling classes that extend Exception.

Given the following source:

class Foo(object):
def __init__(self, m):

class Bar(Exception):
def __init__(self, m):

import pickle
pickle.loads(s) # normal object works
pickle.loads(s) # exception object fails

When running this in Python 2.5 or Python 2.6a, it crashes on the last line, with:

Traceback (most recent call last):
File "", line 14, in <module>
pickle.loads(s) # exception object fails
File "C:\Python25\lib\", line 1374, in loads
return Unpickler(file).load()
File "C:\Python25\lib\", line 858, in load
File "C:\Python25\lib\", line 1133, in load_reduc
value = func(*args)
TypeError: __init__() takes exactly 2 arguments (1 given)
This used to work fine in Python 2.3 and 2.4...
What has been changed in 2.5? Is there a way to get rid of the error?
(I tried some stuff with __getinitargs__ and __getnewargs__ but couldn't get it to work).
Jun 27 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.