[Python-ideas] Adding __getter__ to compliment __iter__.
Masklinn
masklinn at masklinn.net
Fri Jul 19 09:08:08 CEST 2013
On 19 juil. 2013, at 04:59, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On 19 July 2013 00:29, Ron Adam <ron3200 at gmail.com> wrote:
>> I was thinking a generator would be more efficient if it's called many
>> times. But I think this is easier to understand. If there is more interest
>> we can test both to see how much of a difference it makes.
>
> Suspending and resuming a generator is quite an expensive operation.
> send() has the triple whammy of method call + resume generator +
> suspend generator, so it's unlikely to outperform a simple method call
> (even one that redirects to another method).
>
> Independent of performance though, I think the mutable sequence API
> inspired append(), extend() and += are a better API for what you're
> trying to achieve than "send", so it doesn't make sense to me to try
> to shoehorn this into the generator API.
There's an issue with append though, it kind-of implies collection ordering, which I expect is why sets use "add" instead.
More information about the Python-ideas
mailing list