79-装饰器,返回不同颜色的字体
作者:
凯茜的老爸 | 来源:发表于
2018-08-02 10:10 被阅读5次def colors(c):
def set_color(func):
def red(*word):
return '\033[31;1m%s\033[0m' % func(*word)
def green(*word):
return '\033[32;1m%s\033[0m' % func(*word)
adict = {'red': red, 'green': green}
return adict[c]
return set_color
@colors('red')
def hello():
return 'Hello world!'
@colors('green')
def welcome(word):
return 'Hello %s' % word
if __name__ == '__main__':
print(hello()) # -> hello = set_color(hello)
print(welcome('China'))
本文标题:79-装饰器,返回不同颜色的字体
本文链接:https://www.haomeiwen.com/subject/ugkjvftx.html
网友评论