【发布时间】:2013-10-26 14:52:52
【问题描述】:
使用someclass.func 而不是someclass.func() 一直是我的梦想。我读到了@decorators。现在我问:
哪种方式更好?
方式 1
class Main(object):
def __init__(self):
self.func()
def func(self):
print 'hi'
或者...
方式 2
class Main(object):
def __init__(self):
self.func
@property
def func(self):
print 'hi'
编辑
代码如下: http://randomgalaxy.com/stackoverflow/python-property-vs-func/term.py
【问题讨论】:
-
取决于你希望 func() 以后用于什么。
-
这是一个你想要呈现什么API的问题,这完全取决于你的应用和需求。没有上下文,这是无法回答的。
-
@ChristianTernus,我正在使用 wxPython 编写一个 GUI 应用程序。此功能将在我的 StyledTextCtrl 中刷新样式
标签: python function properties