使用函数调用设置Python属性
项目描述
caller
Caller是一个用于将属性作为常规函数调用的库。
安装
使用pip安装
$ pip install caller
用法
from caller import property
class Foo(object):
def __init__(self, bar):
self._bar = bar
@property
def bar(self):
return self._bar
@bar.setter
def bar(self, new_bar):
self._bar = new_bar
foo = Foo('bar')
foo.bar('new bar')
print(foo.bar)
打印
new bar
或使用独立的调用者
class Foo(object):
...
@bar.caller
def bar(self, new_bar):
self._bar = new_bar[::-1]
print(self._bar)
Foo('bar').bar('new bar')
打印
rab wen
这就完了。
项目详情
关闭
caller-0.0.2.tar.gz的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 4dd3b5bf814c0faba5bc580c8969a6ac81b6af918499ce5a157e0157a6775456 |
|
MD5 | facb7ed868fd9aa9589371a1a6b86451 |
|
BLAKE2b-256 | 82a47a32694a0ad44f7f210ceaee3829e739e87f3e8e1e0e4595da371dd32f16 |