Марк Коренберг <[email protected]> added the comment:
#!/usr/bin/python2.7
import json
class pseudo_list(object):
__class__ = list # fake isinstance
def __init__(self, iterator):
self._saved_iterator = iterator
def __iter__(self):
return self._saved_iterator
class myenc(json.JSONEncoder):
def default(self, o):
try:
return pseudo_list(iter(o))
except TypeError:
return super(myenc, self).default(o)
# works (pure-python implementation)
print json.dumps({1:xrange(10), 2:[5,6,7,8]}, cls=myenc, indent=1)
# does not work (C implementation)
print json.dumps({1:xrange(10), 2:[5,6,7,8]}, cls=myenc, indent=None)
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue14886>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com