[Python-ideas] get() method for list and tuples
Barry
barry at barrys-emacs.org
Wed Mar 1 16:04:34 EST 2017
> On 1 Mar 2017, at 19:13, Abe Dillon <abedillon at gmail.com> wrote:
>
> Barry, you're taking the metaphor too far. Duct typing is about presenting a certain interface. If your function takes an object that has a get(key, default) method, the rest doesn't matter. That's the only way in which the object needs to resemble a duck in your function.
In support of get() I found that list of ducks a poor agument for the reasons I stated.
That's not to say that get() on lists may well have value for other reasons, but I find the duck typing a very weak argument.
>
> I'd like to +1 this proposal. It should be trivial to implement. It won't break backward compatibility. It's intuitive. I can think of several places I would use it. I can't think of a good reason not to include it.
I do not think I have encounted any use cases where I would have used this my self.
Maybe in command line processing, I have to dig in my repos and check. Might be able to short cut a length check with a get with default None or "".
Barry
>
>> On Wed, Mar 1, 2017 at 12:06 PM, Barry <barry at barrys-emacs.org> wrote:
>>
>> > On 1 Mar 2017, at 01:26, Michel Desmoulin <desmoulinmichel at gmail.com> wrote:
>> >
>> > - you can iterate on both
>> Maybe, bit do you want the keys, values or (key, value) items? Keys being the deafult.
>> > - you can index both
>> Maybe as you cannot in the general case know the index. Need keys().
>> > - you can size both
>> Yes
>>
>> I think this duck cannot swim or quack.
>>
>> Barry
>>
>>
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170301/75568b94/attachment.html>
More information about the Python-ideas
mailing list