다른 파일에서 import 해 온 함수를 @Decorator 로 싸는 법
조회수 891회
file 1
def file1_fun():
file2
from file1 import file1_fun
def deco(target):
print("데코레이트 되었다네")
def wrapper():
먼저실행할 문장
result = target()
나중에 실행할 문장
return wrapper
@deco
file1_fun() <------------- 이게 말이 안됨. 선언부가 아니라 실행부라서.
이처럼, 외부에서 선언된 파일을 단순히 가져오기만 하는 경우 데코레이터를 어떻게 씌울 수 있습니까?
1 답변
-
자답
from file1 import file1_fun file1_fun = deco(file1_fun)
https://stackoverflow.com/questions/25829364/applying-a-decorator-to-an-imported-function
댓글 입력