Support Decimal
jacobsvante opened this issue · 5 comments
jacobsvante commented
>>> 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)
jacobsvante commented
(Well at least it gives this more precise error when you've merged #34)
quandyfactory commented
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.
quandyfactory commented
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.
quandyfactory commented
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!
jacobsvante commented
Thank you @quandyfactory for fixing this! (Unlike what the README says 😉)