[Python-ideas] get() method for list and tuples

Chris Barker chris.barker at noaa.gov
Fri Mar 3 15:16:48 EST 2017


About JSON and schema-less data:

I need to deal with this fairly often as well, but:

JSON has a data model that includes both mappings and sequences:

Sequences (arrays, lists, etc) are the "right" thing to use when an object
has zero or more of something. Usually, these somethings are all the same.
So you may need to answer the question: how many somethings are there? but
rarely: if there are less than this many somethings, then I should use  a
default value.

Mappings (objects, dicts) are the "right" thing to do when an object has a
bunch of somethings, and each of them may be different and nameable. In
this case, the if this name is in there, use its associated object,
otherwise use a default" is a pretty common action.

so if your JSON is well formed (and I agree, being schema-less does not
mean it is poorly formed) then it should already be using the appropriate
data structures, and you are good to go.

That being said, maybe a concrete example would persuade the skeptics among
us -- though I understand it may be hard to find one that is both
non-trivial and simple and small enough to post to a mailing list...

-CHB








On Fri, Mar 3, 2017 at 12:09 PM, Chris Barker <chris.barker at noaa.gov> wrote:

> On Fri, Mar 3, 2017 at 12:02 PM, Sven R. Kunze <srkunze at mail.de> wrote:
>
>> For me to think (list/tuple).get() was needed would be if lots of folk
>> either cast their lists to dicts or made their own list-dict class to solve
>> that problem.
>>
>>
>> The easier solution would be to provide list.get ;-)
>>
>
> Exactly -- I think that was the point -- if there is a lot of custom code
> out there essentially adding a get() to a list -- then that would indicate
> that is is broadly useful.
>
> For my part, I think casting a list to a dict is often the RIGHT way to
> address these issues.
>
> -CHB
>
>
> --
>
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R            (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
>
> Chris.Barker at noaa.gov
>



-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170303/c1a2242a/attachment-0001.html>


More information about the Python-ideas mailing list