
[Python] :: 데코레이터(decorator) - '@'
·
[Programming Language]/[Python]
◎ 데코레이터(decorator) 데코레이터란 이름에서도 알 수 있듯이 꾸며주는 것을 말한다. 여기서 꾸며주는 것의 대상은 함수와 클래스로 구분할 수 있다. 1) 함수를 꾸며주는 데코레이터 먼저 함수를 꾸며주는 데코레이터부터 살펴보도록 하자. 데코레이터는 '@' 기호를 통해 만들어진다. 아래는 간단한 함수 데코레이터의 예제다. def test(function): # 호출한 함수 'print_hello()'가 매개변수로 들어감 def wrapper(): print(function.__name__, "Start") function() print(function.__name__, "End") return wrapper # 데코레이터 생성 @test def print_hello(): print("Hello !!..