在python里如何使用装饰器

2024-06-16 06:39:29 (54分钟前 更新) 436 3753
# -*- 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

最新回答

不知道,可能不能在装饰器跳出主函数吧
不知道,可能不能在装饰器跳出主函数吧
飞天舞88 2024-06-16
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)
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)
雨天依然美丽 2024-06-01

扩展回答

1

在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.17175889015198 秒