Nyx*_*nyx 7 python oop python-3.x
我试图在一个函数上同时使用@staticmethod
and ,以便结果由and not返回。@property
bar()
Foo.bar
Foo.bar()
但是,Foo.bar
返回的是<property object at 0x107e9cb30>
而不是预期的 string bar
。
为什么@property
装饰器不工作?
def do_work(str):
return str
class Foo:
@property
def foo(self):
return do_work('foo')
@staticmethod
@property
def bar():
return do_work('bar')
f = Foo()
print(f.foo) # foo
print(Foo.bar) # <property object at 0x107e9cb30>
Run Code Online (Sandbox Code Playgroud)
使用Python 3.7.4
归档时间: |
|
查看次数: |
3961 次 |
最近记录: |