ropering / Study

0 stars 0 forks source link

[Python] ... (Ellipsis) / Decorator #36

Open ropering opened 2 years ago

ropering commented 2 years ago
def deco_test(func):
    print("hi_1")
    func()
    print("hi_2")

@deco_test
def main_test():
    print("this is main")

main_test()

# Decorator Class 형태

class Decorator:
  def __init__(self, function):
    self.f = function

  def __call__(self, *args, **kwars):
    print("hi1")
    self.f(*args, **kwars)
    print("hi2")

class MainClass:
  @Decorator
  def main_func_1():
    print("Main start1")

  @Decorator
  def main_func_2():
    print("Main start2")

  @Decorator
  def main_func_3():
    print("Main start3")

test = MainClass
test.main_func_1()
test.main_func_2()
test.main_func_3()

[Python Decorator(데코레이터) @의 의미](https://choice-life.tistory.com/42?category=1096630)

[파이썬 세 개의 점, Ellipsis 객체는 무엇인가요?](https://tech.madup.com/python-ellipsis/)