unpack tuple of wrong size

Duncan Booth me at privacy.net
Wed Apr 7 04:39:35 EDT 2004


Tung Wai Yip <tungwaiyip at yahoo.com> wrote in 
news:c7r57095assq7p777q2ugudnh72qud8kgb at 4ax.com:

> However when
> t = (1,)
> a,b=t
> 
> I got a "ValueError: unpack tuple of wrong size"
> 
> What I want is for a=1 and b=None. Is there a good way to do this?

Probably the simplest is:

a, b = (t + (None, None))[:2]




More information about the Python-list mailing list