装饰用参数注入

时间:2011-07-11 14:47:43

标签: python

我想在另一个类的方法类中注入一个装饰器。

我有以下界面:

class Interface(object):

    __metaclass__ = abc.ABCMeta


    @abc.abstractmethod
    def run(self):
        """Run the process."""
        return

我的班级使用界面

class Launch(Interface):

    def run(self):
        pass

我想要做的是将我的接口类中的装饰器(有参数)注入我的启动类。

我尝试使用Decorator injector,但没有成功。

实现此类功能的最佳方式是什么?

1 个答案:

答案 0 :(得分:0)

使用您的帮助我创建了以下函数来检测实现是否已完成:

  modpath = "C:/mypath"

            for modname in listdir(modpath):
                if modname.endswith(".py"):
                    # look only in the modpath directory when importing
                    oldpath, path[:] = path[:], [modpath]
                    if not modname[:-3]=="__init__":
                        module=__import__(modname[:-3])
                        if  not module.__dict__.has_key("ProcessInterface") :
                                print module.__name__
相关问题