What use is '() here?
Robert
rxjwg98 at gmail.com
Fri Jan 8 12:43:30 EST 2016
Hi,
Thanks Ian for replying to my previous post. Here is a further question on
the 'return' line below.
import collections
import pickle
class C(collections.defaultdict):
def __init__(self):
collections.defaultdict.__init__(self, list)
def __reduce__(self):
t = collections.defaultdict.__reduce__(self)
return (t[0], ()) + t[2:]
c=C()
print c
print c.__reduce__()
c[1].append(200)
c[2].append(223)
c2 = pickle.loads(pickle.dumps(c))
c2 == c
///////////
>From below command, I see 't' should be a tuple:
c.__reduce__()
Out[103]: (__main__.C, (), None, None, <dictionary-itemiterator at 0xaa0dd68>)
Then, I cannot get the idea what the two level parenthesis are for.
Its result is a tuple? Then, it can add 't[2:]'.
return (t[0], ()) + t[2:]
It is not a tuple because there is no third level parenthesis, i.e.
((t[0], ()) + t[2:])
Do you have a simple way for me to make it clear? Thanks,
More information about the Python-list
mailing list