使用函数调用设置python属性
caller的Python项目详细描述
呼叫者
caller是一个小库,用于将属性作为常规函数调用。
安装
使用pip安装:
$ pip install caller
用法
fromcallerimportpropertyclassFoo(object):def__init__(self,bar):self._bar=bar@propertydefbar(self):returnself._bar@bar.setterdefbar(self,new_bar):self._bar=new_barfoo=Foo('bar')foo.bar('new bar')print(foo.bar)
打印
new bar
或者单独打电话
classFoo(object):...@bar.callerdefbar(self,new_bar):self._bar=new_bar[::-1]print(self._bar)Foo('bar').bar('new bar')
打印
rab wen
就这些。