logo       

Re: #99: Patch for cursor.execute and cursor.executemany to return cursor o: msg#00003

python.db.psycopg.devel

Subject: Re: #99: Patch for cursor.execute and cursor.executemany to return cursor object

Miki Tebeka wrote:

>#99: Patch for cursor.execute and cursor.executemany to return cursor object
>-------------------------------------------------+--------------------------
> Reporter: Miki Tebeka <miki.tebeka-Re5JQEeQqe8AvxtiuMwx3w@xxxxxxxxxxxxxxxx>
> | Owner: fog
> Type: defect | Status: new
> Priority: normal | Milestone: PSYCOPG 2.0
>Component: psycopg2 | Version: 2.0beta
> Severity: patch | Keywords:
>-------------------------------------------------+--------------------------
> This patch makes `cursor.execute` and `cursor.executemany` return the
> cursor object.
> This way you can write:
> {{{
> #!python
> for login, in cursor.execute("select login from users"):
> print login
> }}}
>
>


I assume that you really meant to write this:
for login, in cursor.execute("select login from users").fetchone():
print login

which does save a few keystrokes over the current:
cursor.execute("select login from users")
for login, in cursor.fetchone():
print login

Although there is some appeal to the one-liner approach, it is important
to remember that most of the external interface of psycopg is not
actually dictated by psycopg: it's the Python DBAPI. We can't
arbitrarily invent new behaviors.

I agree with Federico on this. Some day, the DBAPI crew may decide that
execute() should return something (success/failure code? record count?
I don't know), and psycopg needs to be able to respond to that without
breaking existing applications.

--
Tim Roberts, timr-EQQNi8F+HVEAvxtiuMwx3w@xxxxxxxxxxxxxxxx
Providenza & Boekelheide, Inc.


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise