J
jbauer
I was interested in playing around with Decimal and
subclassing it. For example, if I wanted a special
class to permit floats to be automatically converted
to strings.
from decimal import Decimal
class MyDecimal(Decimal):
def __init__(self, value):
if isinstance(value, float):
... initialize using str(float) ...
In the classic days, I would have added something
like this to MyDecimal __init__:
Decimal.__init__(self, str(value))
But I'm unfamiliar with the __new__ protocol.
Jeff Bauer
Rubicon, Inc.
subclassing it. For example, if I wanted a special
class to permit floats to be automatically converted
to strings.
from decimal import Decimal
class MyDecimal(Decimal):
def __init__(self, value):
if isinstance(value, float):
... initialize using str(float) ...
In the classic days, I would have added something
like this to MyDecimal __init__:
Decimal.__init__(self, str(value))
But I'm unfamiliar with the __new__ protocol.
Jeff Bauer
Rubicon, Inc.