unpack tuple of wrong size
Andres Rosado-Sepulveda
arosado at softhome.net
Tue Apr 6 14:56:21 EDT 2004
Tung Wai Yip wrote:
> I want to do
>
> t = (1,2)
> a,b = t # get a=1 and b=2
>
> 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?
t = (1,None)
a,b = t
(1,) means that the tuple has only one element. Remember that tuples are
defined by the comma, except on those cases where it would be unclear
what the intention is.
--
Andres Rosado
Email: andresr at despammed.com
Homepage: http://andres980.tripod.com/
"Well, well. Look-who's-BACK!"
-- Megatron
More information about the Python-list
mailing list