def to_dict(obj, classkey=None):
if isinstance(obj, dict):<EOL><INDENT>data = {}<EOL>for (k, v) in obj.items():<EOL><INDENT>data[k] = to_dict(v, classkey)<EOL><DEDENT>return data<EOL><DEDENT>elif hasattr(obj, "<STR_LIT>"):<EOL><INDENT>return to_dict(obj._ast())<EOL><DEDENT>elif hasattr(obj, "<STR_LIT>") and not isinstance(obj, str):<EOL><INDENT>return [to_dict(v, classkey) for v in obj]<EOL><DEDENT>elif hasattr(obj, "<STR_LIT>"):<EOL><INDENT>if six.PY2:<EOL><INDENT>data = dict([(key, to_dict(value, classkey))<EOL>for key, value in obj.__dict__.iteritems()<EOL>if not callable(value) and not key.startswith('<STR_LIT:_>')])<EOL><DEDENT>else:<EOL><INDENT>data = dict([(key, to_dict(value, classkey))<EOL>for key, value in obj.__dict__.items()<EOL>if not callable(value) and not key.startswith('<STR_LIT:_>')])<EOL><DEDENT>if classkey is not None and hasattr(obj, "<STR_LIT>"):<EOL><INDENT>data[classkey] = obj.__class__.__name__<EOL><DEDENT>return data<EOL><DEDENT>else:<EOL><INDENT>return obj<EOL><DEDENT>
Recursively converts Python object into a dictionary