메뉴 바로가기 검색 및 카테고리 바로가기

한빛미디어

뇌를 자극하는 파이썬

뇌를 자극하는 파이썬 질의응답 게시판입니다.

09/decorator1.py 예제 수정(개선) 건의

2016-12-31

|

by youngki6

1400

class MyDecorator:

    def __init__(self,f):

        print("Initializing MyDecorator...")

        self.func = f

 

    def __call__(self):

        print("Begin :{0}".format(self.func.__name__))

        self.func()

        print("End :{0}".format(self.func.__name__))

 

def print_hello():

    print("Hello.")

 

#print_hello = MyDecorator(print_hello)

my_decorator = MyDecorator(print_hello)

 

#print_hello()

my_decorator()

 

위와 같이 수정하면 어떨까요?

 

 

댓글 입력