43213 发表于 2015-11-12 09:10:08

python 装饰器

#!/usr/bin/env python
def deco(func1):            #define a decorate function deco
    def wrapper():
      print"Hello Python!"
      func()
      print"I am Profero!"
    return wrapper
   
@deco                         #use @deco call
def func2():                  #define func2
    print"What's your name? "
   
func2                         #call func2

# The result:
Hello Python!
What's your name?
I am Profero!


页: [1]
查看完整版本: python 装饰器