P
Paul McGuire
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
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