quandyfactory / dicttoxml

Simple library to convert a Python dictionary or other native data type into a valid XML string.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Checking int the "convert_list" function.

akryazhev opened this issue · comments

elif type(item) in (list, set, tuple):
May be this checking is too narrow? It will be cool to make it more wide.
For example, let it to use any iterable Python-object.

Looking into this, it seems I may be better off using the isinstance() function rather than the type() function. The advantage is that isinstance() recognizes the base class of derived classes, such that:

from collections import OrderedDict
test = OrderedDict({ 'foo': 'bar' })
type(test) == dict
False
isinstance(test, dict)
True

So if I test for isinstance(item, dict) the function will work for dict-like objects as well as pure dicts.

Yes, I think this variant is better the previous too. I think it is make sense to wide this checking too:

type(v) in (list, set, tuple)
for example:
import collections
isinstance(v, collections.Iterable):

Fixed in version 1.3. Thanks again for recommending a good change to the library.