What use is '() here?

Robert rxjwg98 at gmail.com
Fri Jan 8 13:04:07 EST 2016


On Friday, January 8, 2016 at 12:44:01 PM UTC-5, Robert wrote:
> 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,

OK. I get my answer for it. It is a tuple. I should get familiar with the
return line. Thanks,



More information about the Python-list mailing list