[BangPypers] Unpacking Tuple
gora at mimirtech.com
Sat Oct 6 12:39:41 CEST 2012
On 6 October 2012 15:39, Saju M <sajuptpm at gmail.com> wrote:
> I am using python 2.6.
> I need a way to make following code working without any ValueError .
> >>> a, b, c, d = (1,2,3,4)
> >>> a, b, c, d = (1,2,3).
> Note: Number of values in the tuple will change dynamically.
Is the maximum length of the tuple fixed?
If so, you can pad the tuple with "blank" variables to
this maximum length, viz.,
NMAX = 4
UNKNOWN_VAL = ''
t = (1, 2, 3)
a, b, c, d = t + (NMAX - len(t)) * (UNKNOWN_VAL,)
If the maximum length is not fixed, you should probably
revisit your design.
More information about the BangPypers