I have a class with a handful of instance variables, which I set through functions decorated with the @someinstancevariable.setter
decorators. How would I go about ensuring that the values set have a maximum and a minimum value to which they could be set? And would I need to have multiple decorators for this or is there some way I can use the regular @someinstancevariable.setter
decorator and override it?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Note that
property
is really a specific implementation of a descriptor, and you can roll your own:This would be used like:
I've posted a fancier descriptor method here with automagical
name
-setting...