Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Jussi Piitulainen Newsgroups: comp.lang.python Subject: Re: Casting to a "number" (both int and float)? Date: Fri, 28 Aug 2015 09:15:09 +0300 Organization: A noiseless patient Spider Lines: 30 Message-ID: References: <0bdda01a-de29-4742-9851-0617dad602ae@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="305c68510616a2e7ac08bcd2ff1598bd"; logging-data="29208"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+JAhKYrzU5PaKA+7U+ZErlmo3DCx7dBYg=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:svgLzo7ifbXrmC+ndb8akaZt0xY= sha1:RlH2rh/fI67CA3Gfykx5TvunaRU= Xref: csiph.com comp.lang.python:95725 Ben Finney writes: > Victor Hooi writes: [- -] >> For example: >> >> { >> "hostname": "example.com", >> "version": "3.0.5", >> "pid": { >> "floatApprox": 18403 >> } >> "network": { >> "bytesIn": 123123, >> "bytesOut": { >> "floatApprox": 213123123 >> } >> } [- -] > In JSON there is no distinction at all, the only numeric type is > ‘float’. What information is there in the input that can be used to > know which values should result in an ‘int’ instance, versus values > that should result in a ‘float’ instance? I seem to get ints in the example data. >>> json.load(io.StringIO('{"floatApprox":31213}')) {'floatApprox': 31213}