Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95733
| Path | csiph.com!goblin2!goblin.stu.neva.ru!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; '(using': 0.07; 'subject:number': 0.07; 'cc:addr:python-list': 0.09; 'input,': 0.09; 'subject:both': 0.09; 'def': 0.13; 'api,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'json,': 0.16; 'pythonic': 0.16; 'subject:)?': 0.16; 'wrote:': 0.16; 'integer': 0.18; 'input': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'aug': 0.20; 'fairly': 0.22; 'are.': 0.22; 'converted': 0.22; 'code.': 0.23; 'bit': 0.23; 'seems': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'workaround': 0.29; "i'm": 0.30; 'minimal': 0.30; 'skip:s 30': 0.31; 'received:google.com': 0.35; 'acceptable': 0.35; 'path': 0.35; 'but': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'data': 0.39; 'field': 0.60; 'your': 0.60; 'chrisa': 0.84; "it'd": 0.84; 'subject:Casting': 0.84; 'victor': 0.84; 'to:none': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=DVUQuUcFgDOBqfF6yoB4edN5+iwPKWm4SWGan7TCb74=; b=FrBorBcayyoMp4UAV+6RItB33o4mFK6IXUZhFyvSRDWoCy0M6K/RBVwN9iE/YUAQ6N Mc+wbmNxMk8Wmys2yG2795OGu+PwnsgmWeWws67OzotLsLl7pJ2MhXHs7HudCNtSQoq+ v1sPWxlNgLNckrx1I/iPPESR6/8z5OyNgYOzgcpb3nw+Q9a/7rKAFM0qJcxb+2XoeJfG J/lfagGaFm4yC9K7BgV5k4A4SIF0L4/9dTWPNLdXCG1IITVxGmCw+2/VnrIZ1e31nK7E teRrGz7bpO0RkIA7gIpunMyAQlWhi4GRAz/Hz8TqBg4zH6tcHF82hPktRzn4PWoiDXuO 0ucA== |
| MIME-Version | 1.0 |
| X-Received | by 10.50.118.104 with SMTP id kl8mr2568648igb.92.1440753839004; Fri, 28 Aug 2015 02:23:59 -0700 (PDT) |
| In-Reply-To | <b172ba55-2188-4f83-ac5e-1311e9a51428@googlegroups.com> |
| References | <0bdda01a-de29-4742-9851-0617dad602ae@googlegroups.com> <mailman.96.1440740667.11709.python-list@python.org> <lf5wpwgj5w2.fsf@ling.helsinki.fi> <b172ba55-2188-4f83-ac5e-1311e9a51428@googlegroups.com> |
| Date | Fri, 28 Aug 2015 19:23:58 +1000 |
| Subject | Re: Casting to a "number" (both int and float)? |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.107.1440753847.11709.python-list@python.org> (permalink) |
| Lines | 20 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1440753847 news.xs4all.nl 23768 [2001:888:2000:d::a6]:45592 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:95733 |
Show key headers only | View raw
On Fri, Aug 28, 2015 at 5:56 PM, Victor Hooi <victorhooi@gmail.com> wrote: > > Currently I'm using this: > > def strip_floatApprox_wrapping(field): > # Extracts a integer value from a field. Workaround for the float_approx wrapping. > if isinstance(field, dict): > return field['floatApprox'] > else: > return field > > I was a little hesitant to go down that path (using isinstance()) since it seems a bit "un-Pythonic" but it seems to do what I want in a minimal amount of code. It'd not be as Pythonic if this were an API, but since you just converted this from JSON, you can be fairly confident of what the data types are. You're dealing with your program's input, and that input can come in a specific number of forms; so you cope with each form. This is a perfectly acceptable and reasonable way to write code. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Casting to a "number" (both int and float)? Victor Hooi <victorhooi@gmail.com> - 2015-08-27 21:57 -0700
Re: Casting to a "number" (both int and float)? Victor Hooi <victorhooi@gmail.com> - 2015-08-27 22:04 -0700
Re: Casting to a "number" (both int and float)? "Sven R. Kunze" <srkunze@mail.de> - 2015-08-28 18:09 +0200
Re: Casting to a "number" (both int and float)? Robin Koch <robin.koch@t-online.de> - 2015-08-28 18:15 +0200
Re: Casting to a "number" (both int and float)? "Sven R. Kunze" <srkunze@mail.de> - 2015-08-30 13:38 +0200
Re: Casting to a "number" (both int and float)? Steven D'Aprano <steve@pearwood.info> - 2015-08-30 22:00 +1000
Re: Casting to a "number" (both int and float)? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-08-30 13:55 +0100
Re: Casting to a "number" (both int and float)? Ben Finney <ben+python@benfinney.id.au> - 2015-08-28 15:44 +1000
Re: Casting to a "number" (both int and float)? Jussi Piitulainen <harvestingn@makes.address.invalid> - 2015-08-28 09:03 +0300
Re: Casting to a "number" (both int and float)? Jussi Piitulainen <harvesting@makes.address.invalid> - 2015-08-28 09:15 +0300
Re: Casting to a "number" (both int and float)? Victor Hooi <victorhooi@gmail.com> - 2015-08-28 00:56 -0700
Re: Casting to a "number" (both int and float)? Chris Angelico <rosuav@gmail.com> - 2015-08-28 19:23 +1000
Re: Casting to a "number" (both int and float)? Jussi Piitulainen <harvesting@makes.address.invalid> - 2015-08-28 08:46 +0300
Re: Casting to a "number" (both int and float)? random832@fastmail.us - 2015-08-28 01:54 -0400
Re: Casting to a "number" (both int and float)? Laura Creighton <lac@openend.se> - 2015-08-28 07:59 +0200
csiph-web