470,849 Members | 659 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

unpack tuple of wrong size

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?
Wai Yip Tung
Jul 18 '05 #1
2 3078
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: an*****@despammed.com
Homepage: http://andres980.tripod.com/

"Well, well. Look-who's-BACK!"
-- Megatron
Jul 18 '05 #2
Tung Wai Yip <tu********@yahoo.com> wrote in
news:c7********************************@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]

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by grant | last post: by
3 posts views Thread by Linh Luong | last post: by
3 posts views Thread by Eric Jacoboni | last post: by
3 posts views Thread by Andrew Robert | last post: by
4 posts views Thread by OhKyu Yoon | last post: by
3 posts views Thread by echo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.