Support Decimal
jacobsvante opened this issue · comments
>>> import dicttoxml
>>> from decimal import Decimal
>>> mydict = dict(mydecimal=Decimal('1.2345'))
>>> dicttoxml.convert_dict(mydict, False, 'objects', True)
TypeError: Unsupported data type: 1.2345 (Decimal)
(Well at least it gives this more precise error when you've merged #34)
You're right; dicttoxml should be able to accommodate Decimal values. Let me look into how best to implement this and I will push a fix shortly.
It looks like the most generic way to test if an object is a number is to import numbers
and then:
isinstance(mydecimal, numbers.Number)
Unless I find anything better, I'm going to implement this.
I went with isinstance(mydecimal, numbers.Number)
as it seems to be the most generic way to test if something is numbery. Thanks for bringing this issue to my attention!
Thank you @quandyfactory for fixing this! (Unlike what the README says 😉)