![](/img/trans.png)
[英]'cached_property' object has no attribute 'get', Request.args.get
[英]AttributeError: 'cached_property' object has no attribute 'setter'
我正在使用 functools.cached_property 來記憶一些功能。
但它似乎不支持二傳手。
例如
class User
@cached_property
def name(self):
return self._name
@name.setter
def name(self, val):
self._name = val
但是在導入時我遇到了AttributeError: 'cached_property' object has no attribute 'setter'
@cached_property 專為不可變值而設計。 你不能指望這個裝飾器會模仿標准屬性的所有特性。 在 python 文檔中,您可以找到:“cached_property() 的機制與 property() 有所不同。除非定義了 setter,否則常規屬性會阻止屬性寫入。相反,cached_property 允許寫入。”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.