轻松委派
smartcompose的Python项目详细描述
用^{tt1}修饰类$ 将method_names中的方法委托给属性attribute_name:
In[1]:fromsmartcomposeimportdelegateIn[2]:@delegate('_n',('__add__','__mul__'))...:classNumberWrapper:...:def__init__(self,n):...:self._n=n...:In[3]:n=NumberWrapper(10)In[4]:n+2Out[4]:12In[5]:n*3Out[5]:30
目前,只与Python3兼容。
pip install smartcompose