getter

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

does the @property decorator function as a getter?

does the @property decorator function as a getter? Question: i am new to python and i’m trying to understand the use of the ‘getter’. it’s use case is not obvious to me. if i use a property decorator on a method and im able to return a certain value, what exactly would i use ‘getter’ …

Total answers: 2

Python read-only lists using the property decorator

Python read-only lists using the property decorator Question: Short Version Can I make a read-only list using Python’s property system? Long Version I have created a Python class that has a list as a member. Internally, I would like it to do something every time the list is modified. If this were C++, I would …

Total answers: 6

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