在python里如何使用装饰器?



                    
                    
穿风衣的猫2012
34029 次浏览 2024-06-08 提问
79

最新回答 (2条回答)

2024-06-08 回答

不知道,可能不能在装饰器跳出主函数吧

追问那有什么方法可以退出主函数呢,不一定要用装饰器的,其他的也行。
2024-06-08 回答

class Pizza(object):
def decoratePizza: pass
def __call__:
print "make a pizza"
class CheeryPizza(Pizza):
def decoratePiza:
print "cherry Pizza"
def __call__:
print "dec供怠垛干艹妨讹施番渐orate with what"
if __name__ == '__main__':
test = CheeryPizza
apply(test)

追问看不明白,我想的是如何使用一个通用的函数来退出主函数,但要继续执行下一个函数或其他代码

扩展回答

在python里如何使用装饰器

# -*- coding: utf-8 -*-
#coding:UTF-8

def FirstDeco(func):
print u'第一个装饰器'
#if 1>0:return True
return func
@供怠垛干艹妨讹施番渐FirstDeco
def test0():
if 1>0:return True #这条判断语句很多地方要用到,如何抽取出来用一个函数装饰器包装起来用。

print 'test0'
def test1():
print 'test1'
test0()
test1()
#只要输出 test1

相关问题

页面运行时间: 0.094264030456543 秒