嗨,这是python中的新手,我想编写一个优先装饰器,它将根据传递给装饰器的优先级值决定必须实例化哪个类实例。
# abstract class
class Base:
def method1(self):
pass
@deco(priority=1)
class A(Base):
def method1(self):
pass
@deco(priority=3)
class B(Base):
def method1(self):
pass
@deco(priority=2)
class C(B):
def method1(self):
pass
def return_class_obj():
# this method will return the object based upon the priority of the
# class passed through decorator