Decorator-like syntax for a specific line of code
问题 Linked topic (but not duplicate): Decorator to time specific lines of the code instead of whole method? I know how decorators are usually used for Python functions. Is there a similar concept/syntax for single lines of code? Example: with def measuretime(lineofcode): start = time.time() lineofcode() print time.time() - start then @measuretime im = Image.open(BytesIO(base64.b64decode(data))) would be interpreted like start = time.time() im = Image.open(BytesIO(base64.b64decode(data))) print