On this page
article
Property Validation
Validate attributes with @property.
Category: oop
Problem
Validate attributes with @property.
Solution
@age.setter
def age(self, v):
if v < 0: raise ValueError('invalid')
Notes
- Adapt variable names and paths to your project
- Add error handling for production use
- See related chapters in the Learning Path