Applying a decorator to an imported function?
问题 I want to import a function: from random import randint and then apply a decorator to it: @decorator randint I was wondering if there was some syntactic sugar for this (like what I have above), or do I have to do it as follows: @decorator def randintWrapper(*args): return random.randint(*args) 回答1: Decorators are just syntactic sugar to replace a function object with a decorated version, where decorating is just calling (passing in the original function object). In other words, the syntax: