Reputation: 1828
I have this Python 2 code:
class VKHandshakeChecker:
def __getAnswers(self):
return self.__answers
def __getStatus(self):
return self.__status
def __init__(self,vkapi,maxDepth=6):
isinstance(vkapi,VKApi.VKApi)
self.vkapi = vkapi
self.__maxDepth=maxDepth
self.__answers = list()
self.__status = 'IDLE'
self.status = property(VKHandshakeChecker.__getStatus)
self.answers = property(VKHandshakeChecker.__getAnswers)
I want to get answers
property. But when I execute this code:
checker = VKHandshakeChecker.VKHandshakeChecker(api)
print(checker.status)
I get <property object at 0x02B55450>
, not IDLE
. Why?
Upvotes: 1
Views: 4939
Reputation: 1121216
You can't put descriptors (like a property
object) on the instance. You have to use them on the class.
Simply use property
as a decorator:
class VKHandshakeChecker:
@property
def answers(self):
return self.__answers
@property
def status(self):
return self.__status
def __init__(self,vkapi,maxDepth=6):
self.vkapi = vkapi
self.__maxDepth=maxDepth
self.__answers = list()
self.__status = 'IDLE'
I removed the isinstance()
expression, it doesn't do anything as you are ignoring the return value of the function call.
Upvotes: 5