SHARE
TWEET

Untitled

a guest Jun 19th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Traceback (most recent call last):
  2.   File "bar.py", line 10, in <module>
  3.     pickle.loads(pickle.dumps(foo))
  4. TypeError: __new__() takes 1 positional argument but 3 were given
  5.      
  6. from collections import namedtuple
  7. import pickle
  8.  
  9. class Foo(namedtuple("_Foo", ["a", "b"])):
  10.     def __new__(cls, *args, **kwargs):
  11.         self = super().__new__(cls, *args, **kwargs)
  12.         # some custom code
  13.         return self
  14.  
  15. foo = Foo(a=1, b=2)
  16. pickle.loads(pickle.dumps(foo))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top