This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author socketpair
Recipients cvrebert, pitrou, socketpair
Date 2012-05-24.02:29:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1337826550.48.0.16302893547.issue14886@psf.upfronthosting.co.za>
In-reply-to
Content
#!/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)
History
Date User Action Args
2012-05-24 02:29:10socketpairsetrecipients: + socketpair, pitrou, cvrebert
2012-05-24 02:29:10socketpairsetmessageid: <1337826550.48.0.16302893547.issue14886@psf.upfronthosting.co.za>
2012-05-24 02:29:09socketpairlinkissue14886 messages
2012-05-24 02:29:09socketpaircreate