Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.027 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'float': 0.07; 'override': 0.09; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'function;': 0.16; 'nan': 0.16; 'overriding': 0.16; 'subclass': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'thu,': 0.19; 'code,': 0.22; 'suggested': 0.26; 'post': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; '(which': 0.31; 'though.': 0.31; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'to:addr:python-list': 0.38; 'that,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'read': 0.60; 'simply': 0.61; 'more': 0.64; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=itH6XsFO2QMaQXD1Lp5I+pWDZ9PVmH0fM9hdFfG63OE=; b=gQn/JWrRXdwo0RH4prXE4hIIFXUpiRHjFvzzCtxSK+SBO6vvEQHMO220psYob80gDn am3ON259IL+/ZQowXUEPbJ/VGDpNl/GvSdEk+dAQfvxwcO6YLXRb//Dbf8xL7PKP/IlY 3GI2Y31ZpnE+UkXU+WjZtn5TQvD373e296WnKAdrKcY0aq/bUDyBG6pvBBwPVNhw2DFT mzsDGoLFgO8sUdEg5qT81XWxVfLK8xQDynrEJ4hrJOFpud8IjhomTYDYkbppKrTpaOr7 rlDeCGWzudrwcF5p056aGkr62W8GhKBoS5kTEeIfHaeHizhHIyYP0VqzclxXqi9P5Hht vVrQ== MIME-Version: 1.0 X-Received: by 10.58.56.161 with SMTP id b1mr6822865veq.42.1366249307418; Wed, 17 Apr 2013 18:41:47 -0700 (PDT) In-Reply-To: <1040891b-d350-4304-8112-de4a383562dc@googlegroups.com> References: <1040891b-d350-4304-8112-de4a383562dc@googlegroups.com> Date: Thu, 18 Apr 2013 11:41:47 +1000 Subject: Re: Encoding NaN in JSON From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 12 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366249316 news.xs4all.nl 2180 [2001:888:2000:d::a6]:60613 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43796 On Thu, Apr 18, 2013 at 11:01 AM, Miki Tebeka wrote: > [Roland] >> yes, there is: subclass+extend the JSON-encoder, see pydoc json. > Please read the original post before answering. What you suggested does not work since NaN is of float type. You may be able to override a bit more of the code, though. Check out Lib/json/encoder.py for the implementation, and have a look at the floatstr() internal function; unfortunately you can't simply subclass and override that, but perhaps overriding iterencode (which is where floatstr is defined) would do the job. ChrisA