setter

problem defining class property in python

problem defining class property in python Question: I’m new to python programming, I’m trying to encapsulate all property checking of a size in the class object below but one of them is not working (checking to see if withdraw is bigger than amount of books inside the shelf): class Shelf: def __init__(self, capacity=12): self.capacity = …

Total answers: 1

Python overriding getter without setter

Python overriding getter without setter Question: class human(object): def __init__(self, name=”): self.name = name @property def name(self): return self._name @name.setter def name(self, value): self._name = value class superhuman(human): @property def name(self): return ‘super ‘ + name s = superhuman(‘john’) print s.name # Doesn’t work 🙁 “AttributeError: can’t set attribute” s.name = ‘jack’ print s.name I …

Total answers: 1

Using both __setattr__ and descriptors for a python class

Using both __setattr__ and descriptors for a python class Question: I’m writing a python class that uses __setattr__ and __getattr__ to provide custom attribute access. However, some attributes can’t be handled in a generic way, so I was hoping to use descriptors for those. A problem arises in that for a descriptor, the descriptor’s __get__ …

Total answers: 2