3 ms·
In Python the equivalent is namedtuples, which IMO is better syntax anyway because you can use named arguments: import collections Key = collections.n
by yawaramin 9y ago
In Python the equivalent is namedtuples, which IMO is better syntax anyway because you can use named arguments:
import collections
Key = collections.namedtuple('Key', ['modifier', 'key', 'function', 'argument'])
keys = [
Key(modifier=MODKEY, key=XK_p, function=spawn, argument=dmenucmd),
Key(modifier=MODKEY|ShiftMask, key=XK_Return, function=spawn, argument=termcmd),
Key(modifier=MODKEY, key=XK_b, function=togglebar, argument=0),
Key(modifier=MODKEY, key=XK_j, function=focusstack, argument=+1),
Key(modifier=MODKEY, key=XK_k, function=focusstack, argument=-1)
]
- tom_mellior 9y agoThat does add a lot of redundant noise on each line, though. I would write this particular case as normal tuples which I would then turn into Keys in a separate step: keys = [Key(*tuple) for tuple in keys] Another possibility is to keep the Key constructor on each line, but to get rid of the keyword arguments, which are not mandatory: >>> Key('a', 'b', 'c', 'd') Key(modifier='a', key='b', function='c', argument='d')