2 ms·
Take a look at https://github.com/python-attrs/attrs https://github.com/python-attrs/attrs which will let you do something like import attr @attr.s
by geofft 9y ago
Take a look at https://github.com/python-attrs/attrs https://github.com/python-attrs/attrs which will let you do something like
import attr
@attr.s
class Key(object):
modifier = attr.ib()
key = attr.ib()
function = attr.ib()
argument = attr.ib()
keys = [
Key(MODKEY, XK_p, spawn, {'v': dmenucmd}),
Key(MODKEY|ShiftMask, XK_Return, spawn, {'v': termcmd}),
# ...
]
which gets you the concise and readable syntax of C structs, while keeping these things as actual attributes as if they were classes (e.g., [key.modifier for key in keys] will work).
And you get designated initializers via Python's usual keyword-argument syntax, the ability to specify attr.ib(default=...), and a few other things.