Python @properity 在原子编辑器中自动完成
Python @properity autocomplete in atom editor
我正在使用 atom 在 python 中定义一个 @属性。所以自动完成给了他们这个:
def test():
doc = "The test property."
def fget(self):
return self._test
def fset(self, value):
self._test = value
def fdel(self):
del self._test
return locals()
test = property(**test())
其中test是我定义的名字。我不明白这段代码的作用以及如何使用它?
使用它而不是在 python 中使用 getter 和 setter 的传统方式有什么不同吗?
我将不胜感激
您的文本编辑器只是向您展示了不使用装饰器而使用 property
的替代方法。官方 Python 文档中的示例也显示了这一点。 property
本身是一个 class,它采用 fget
、fset
、fdel
和 doc
的关键字参数。在您的示例中,您有 test
return 所有与关键字参数匹配的函数,然后使用解包将它们作为参数输入。这显示在文档 here.
中
我正在使用 atom 在 python 中定义一个 @属性。所以自动完成给了他们这个:
def test():
doc = "The test property."
def fget(self):
return self._test
def fset(self, value):
self._test = value
def fdel(self):
del self._test
return locals()
test = property(**test())
其中test是我定义的名字。我不明白这段代码的作用以及如何使用它? 使用它而不是在 python 中使用 getter 和 setter 的传统方式有什么不同吗?
我将不胜感激
您的文本编辑器只是向您展示了不使用装饰器而使用 property
的替代方法。官方 Python 文档中的示例也显示了这一点。 property
本身是一个 class,它采用 fget
、fset
、fdel
和 doc
的关键字参数。在您的示例中,您有 test
return 所有与关键字参数匹配的函数,然后使用解包将它们作为参数输入。这显示在文档 here.