带参数注入的装饰器
我想在一个类的方法上添加装饰器,而这个装饰器来自另一个类。
我有一个这样的接口:
class Interface(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def run(self):
"""Run the process."""
return
我有一个使用这个接口的类:
class Launch(Interface):
def run(self):
pass
我想做的是从我的接口类中,把带参数的装饰器注入到我的Launch类里。
我尝试过使用装饰器注入器,但没有成功。
实现这个功能的最佳方法是什么呢?
1 个回答
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__