在python中,这个'返回装饰器(回调),如果回调其他装饰器'是什么意思?

0 python if-statement return

def method(path,method,callback) 
    def decorator(callback):if isinstance(callback, basestring): callback = load(callback)
        for rule in makelist(path) or yieldroutes(callback):
            for verb in makelist(method):
                verb = verb.upper()
                route = Route(self, rule, verb, callback, name=name,
                              plugins=plugins, skiplist=skiplist, **config)
                self.add_route(route)
    return callback
return decorator(callback) if callback else decorator
Run Code Online (Sandbox Code Playgroud)

最后一句话是什么意思?

Lev*_*von 5

return decorator(callback) if callback else decorator
Run Code Online (Sandbox Code Playgroud)

翻译成:

if callback:
   return decorator(callback)
else:
   return decorator
Run Code Online (Sandbox Code Playgroud)

这是Python使用三元表达式的方式.

有关Python是否具有三元条件运算符的更多信息,请参阅此SO问题. .