Idiom for default values when unpacking a tuple

Diez B. Roggisch deetsNOSPAM at web.de
Tue Nov 16 11:53:20 EST 2004


You can always have a try/exept clause around unpacking. That you could
fator out into a function that always returns the right sized tuples. Like
this:

def unpack(t):
    try:
        a,b,c = t
        d = None
    except ValueError:
        a,b,c,d = t
    return a,b,c,d

-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list