Asynchronous programming
Jussi Piitulainen
jussi.piitulainen at helsinki.fi
Thu Aug 11 12:03:05 EDT 2016
Michael Selik <michael.selik at gmail.com> writes:
> On Thu, Aug 11, 2016 at 11:46 AM Michael Selik <michael.selik at gmail.com>
> wrote:
>
>> On Thu, Aug 11, 2016 at 11:01 AM Steven D'Aprano <
>> steve+python at pearwood.info> wrote:
>>
>>> That ... looks wrong. You're taking something which looks like a procedure
>>> in the first case (trn.execute), so it probably returns None, and yielding
>>> over it. Even it that's not wrong, and it actually returned something
>>> which
>>> you ignored in the first case
>>>
>>
>> It's a standard, perhaps a mistaken standard, but nonetheless database
>> cursors tend to have that feature: execute returns the mutated self. I
>> agree that execute looks like it should return None instead. The return
>> self pattern feels Rubyish to me (or Rubic?).
>>
>
> Contradicting myself:
> yield from c.execute(query).fetchall() # looks good
> yield from c.execute(query) # looks bad
The first looks like it allocates a list to hold all the results at once
only to yield each result one by one.
How about:
c.execute(query)
yield from c
More information about the Python-list
mailing list