In this blog article they use the construct:
@measured def some_func(): #... # Presumably outputs something like 'some_func() is finished in 121.333 s' somewhere
This @measured directive doesn’t seem to work with raw python. What is it?
UPDATE: I see from Triptych that @something is valid, but is where can I find @measured, is it in a library somewhere, or is the author of this blog using something from his own private code base?
@measureddecorates the some_func() function, using a function or class namedmeasured. The@is the decorator syntax,measuredis the decorator function name.Decorators can be a bit hard to understand, but they are basically used to either wrap code around a function, or inject code into one.
For example the measured function (used as a decorator) is probably implemented like this…
The decorator syntax is just a shorter and neater way of doing the following:
There are some decorators included with Python, for example
staticmethod– butmeasuredis not one of them:Check the projects
importstatements to see where the function or class is coming from. If it usesfrom blah import *you’ll need to check all of those files (which is whyimport *is discouraged), or you could just do something likegrep -R def measured *