Idiom for default values when unpacking a tuple

Paul McGuire ptmcg at austin.rr._bogus_.com
Tue Nov 16 11:42:57 EST 2004


I'm trying to manage some configuration data in a list of tuples, and I
unpack the values with something like this:

configList = [
    ("A",1,2,3),
    ("F",1,3,4),
    ("X",2,3,4),
    ("T",1,5,4),
    ("W",6,3,4),
    ("L",1,3,8),
    ]
for data in configList:
    name,a,b,c = data
    ... do something with a,b, and c

Now I would like to add a special fourth config value to "T":
    ("T",1,5,4,0.005),

and I would like to avoid having to put 0's or None's in all of the others.
Is there a clean Python idiom for unpacking a tuple so that any unassigned
target values get a default, or None, as in:

    tup = (1,2)
    a,b,c = tup

gives a = 1, b = 2, and c = None.

I've tried creating a padUnpack class, but things aren't quite clicking...

TIA,
-- Paul





More information about the Python-list mailing list