python decorator

    xiaoxiao2021-03-25  179

    http://www.cnblogs.com/SeasonLee/articles/1719444.html

    def salesgirl(method): def serve(*args): print "Salesgirl:Hello, what do you want?", method.__name__ result = method(*args) if result: print "Salesgirl: This shirt is 50$." else: print "Salesgirl: Well, how about trying another style?" return result return serve @salesgirl def try_this_shirt(size): if size < 35: print "I: %d inches is to small to me" %(size) return False else: print "I:%d inches is just enough" %(size) return True result = try_this_shirt(38) print "Mum:do you want to buy this?", result   结果是: Salesgirl:Hello, what do you want? try_this_shirt I:38 inches is just enough Salesgirl: This shirt is 50$. Mum:do you want to buy this? True
    转载请注明原文地址: https://ju.6miu.com/read-3782.html

    最新回复(0)