装饰器,有无内层函数的区别
# !/usr/bin/env python
# -*- coding:utf-8 -*-
def decorator(func):
print('decorator 1')
func()
print('decorator 2')
return func
@decorator
def foo():
print('foo-self')
foo()
# decorator 1
# foo-self
# decorator 2
# foo-self
print('-' * 15)
def outer(func):
def inner():
print("dddd")
func()
print("ssss")
return inner
@outer
def foo():
print("foo")
# foo = outer(foo)
foo()
# dddd
# foo
# ssss