python - 我无法在静态类中创建 python 属性
问题描述
我正在尝试为静态类中的变量创建一个 python 属性。我做了一个简化的尝试:
class c(object):
_a = 5
@staticmethod
def a_get():
print 'getter'
return self._a
@staticmethod
def a_set(new_value):
print 'setter'
self._a = new_value
a = property(a_get, a_set)
def main():
print c.a
if __name__ == '__main__':
main()
我期望发生的事情-它将打印getter 5
实际发生的情况 - 它打印属性本身(<0x000000000308F1D8> 处的属性对象)。
我错过了什么?
解决方案
推荐阅读
- batch-file - 批处理:有没有将 %errorlevel% 转换为 HResult 的函数?
- ios - 如何在 Xamarin.Forms iOS 中实现“软键盘输入模式”并修复键盘重叠问题?
- python - Gzip压缩/解压间隙
- javascript - 如果使用 JS 更改 DOM 中的元素不工作事件
- excel - 在包含 100 多个链接文本文件的 Word 文档中更改链接文件的路径名
- java - 使用 CompletableFuture 或 Future 对象获取 Callable 值
- django - docker 容器中的应用程序再次运行并退出并显示消息 - 文件可能不为空
- python - SAPB1 和 django 集成
- paypal - 如何为本地取货配置 PayPal 智能支付按钮?
- angular - 错误:EPERM:Bitbucket 管道中不允许操作