반응형
이 코드는 오류를 반환합니다. AttributeError : ca n't set attribute 메서드를 호출하는 대신 속성을 사용하고 싶기 때문에 이것은 정말 유감입니다. 이 간단한 예제가 작동하지 않는 이유를 아는 사람이 있습니까?
#!/usr/bin/python2.6
class Bar( object ):
"""
...
"""
@property
def value():
"""
...
"""
def fget( self ):
return self._value
def fset(self, value ):
self._value = value
class Foo( object ):
def __init__( self ):
self.bar = Bar()
self.bar.value = "yyy"
if __name__ == '__main__':
foo = Foo()
해결 방법
이것이 당신이 원하는 것입니까?
class C(object):
def __init__(self):
self._x = None
@property
def x(self):
"""I'm the 'x' property."""
return self._x
@x.setter
def x(self, value):
self._x = value
참조 페이지 https://stackoverflow.com/questions/1684828
반응형
'파이썬' 카테고리의 다른 글
파이썬 웹 사이트가 있는지 Python 확인 (0) | 2021.01.16 |
---|---|
파이썬에서 한 번에 두 개의 목록 값을 반복 (0) | 2021.01.16 |
파이썬에서 날짜 문자열 형식을 어떻게 검증합니까? (0) | 2021.01.16 |
파이썬 PyCrypto not fully installed on Windows XP (0) | 2021.01.16 |
파이썬 Run Python script without Windows console appearing (0) | 2021.01.16 |
댓글