Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #112085
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: JSON result parsing |
| Date | 2016-07-30 17:20 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <87wpk3w11m.fsf@bsb.me.uk> (permalink) |
| References | <fd02ca3a-47af-4a0b-b309-56bc732ea071@googlegroups.com> |
TUA <kai.peters@gmail.com> writes: > Calls to my REST api may either return a dict (for single results) or > a list of dicts (for multiple results). I think John's answer missed this part. > I receive these results using the requests library. > > I want to retrieve the value for a key 'ID' but only if I have a > single result and, obviously, if ID is present. If r is the result of the request, just testing if 'ID' in r: ... whatever ... would do. The result will be False if r is a list or the single result does not have an ID. > How can I do this with pythonic elegance? Ah, that I leave to others. -- Ben.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
JSON result parsing TUA <kai.peters@gmail.com> - 2016-07-29 16:45 -0700 Re: JSON result parsing John Gordon <gordon@panix.com> - 2016-07-30 03:25 +0000 Re: JSON result parsing Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-07-30 17:20 +0100
csiph-web