-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Description
from functools import wraps
def decorator_name(f):
@wraps(f)
def decorated(*args, **kwargs):
if not can_run:
return "함수는 실행되지 않습니다."
return f(*args, **kwargs)
return decorated
@decorator_name
def func():
print "함수가 실행 중입니다."
can_run = True
print(func())
#output: 함수가 실행 중입니다
위의 소스처럼 can_run
이 True
인 상태에서 print(func())
을 실행하면 실행 결과는
함수가 실행 중입니다.
None
으로 None까지 같이 출력됩니다. def decorated()
의 return이 f()
이고, f
에 해당하는 func()
는 return값이 없기 때문에요.
차라리 func()
을
@decorator_name
def func():
return "함수가 실행 중입니다."
으로 하는 게 더 낫지 않을까요?
Metadata
Metadata
Assignees
Labels
No labels