Class PercentageQuantity
source code
object --+
|
PercentageQuantity
Class representing a percentage quantity.
The percentage is maintained internally as a string so that issues of
precision can be avoided. It really isn't possible to store a floating
point number here while being able to losslessly translate back and forth
between XML and object representations. (Perhaps the Python 2.4 Decimal
class would have been an option, but I originally wanted to stay
compatible with Python 2.3.)
Even though the quantity is maintained as a string, the string must be
in a valid floating point positive number. Technically, any floating
point string format supported by Python is allowble. However, it does
not make sense to have a negative percentage in this context.
|
|
|
|
|
|
|
|
|
_setQuantity(self,
value)
Property target used to set the quantity The value must be a
non-empty string if it is not None . |
source code
|
|
|
_getQuantity(self)
Property target used to get the quantity. |
source code
|
|
|
|
Inherited from object :
__delattr__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__setattr__
|
|
quantity
Percentage value, as a string
|
|
percentage
Percentage value, as a floating point number.
|
Inherited from object :
__class__
|
__init__(self,
quantity=None)
(Constructor)
| source code
|
Constructor for the PercentageQuantity class.
- Parameters:
quantity - Percentage quantity, as a string (i.e. "99.9" or
"12")
- Raises:
ValueError - If the quantity value is invaid.
- Overrides:
object.__init__
|
Official string representation for class instance.
- Overrides:
object.__repr__
|
__str__(self)
(Informal representation operator)
| source code
|
Informal string representation for class instance.
- Overrides:
object.__str__
|
Definition of equals operator for this class. Lists within this class
are "unordered" for equality comparisons.
- Parameters:
other - Other object to compare to.
- Returns:
- -1/0/1 depending on whether self is
< ,
= or > other.
|
Property target used to set the quantity The value must be a non-empty
string if it is not None .
- Raises:
ValueError - If the value is an empty string.
ValueError - If the value is not a valid floating point number
ValueError - If the value is less than zero
|
Property target used to get the quantity as a floating point number.
If there is no quantity set, then a value of 0.0 is returned.
|
quantity
Percentage value, as a string
- Get Method:
- _getQuantity(self)
- Property target used to get the quantity.
- Set Method:
- _setQuantity(self,
value)
- Property target used to set the quantity The value must be a
non-empty string if it is not
None .
|
percentage
Percentage value, as a floating point number.
- Get Method:
- _getPercentage(self)
- Property target used to get the quantity as a floating point number.
|