2 ms·
or, more usually one of these: def somefunc(x, y): blabla dec(somefunc) def somefunc(x, y): blabla somefunc = dec(somefunc) T
by cabalamat 16y ago
or, more usually one of these:
def somefunc(x, y):
blabla
dec(somefunc)
def somefunc(x, y):
blabla
somefunc = dec(somefunc)
The rationale for decorators, AIUI, is that if somefunc() is long, then putting the decorator at the end makes it easier to overlook, whereas putting it at the top is harder to overlook. Personally, I never use them; if I want the functionality of decorators, I write code immediately after the function, e.g.:
def add(a, b):
r = a.getValue() + b.getValue()
return sm.UInteger(r)
notify(add, "ii", "i", "+", cascade=True)
BTW, lists, tuples and dicts have been in Python since forever (at least as far back as 0.9.1)