python - How do i add the value that is in createData using @property and use that in putData -
class data(self): def __ init __(self): self._dictlist = [] @property def dictlist(self): return self._dictlist @dictlist.setter def dictlist(self, value): self._dictlist.append(value) def putdata(self): value in self.dictlist: print value def createdata(self): value = 10 self.dictlist = value
how add value in createdata using @property , use in putdata ?
even if still not understand expectation, let's correct what's wrong here:
this not how declare class
class data(self): # incorrect class data(object): # correct
- your dict list ... , should not name dict
then comment propose use heritage:
class data(list): # <-- data list
that way can add values on normal list (ie: list[key] = value
or list.append(value)
or list.insert(index, value)
)
, add custom methods in normal class.
Comments
Post a Comment