Documentation, assignment in expression.

mwilson at mwilson at
Mon Mar 26 01:09:12 CEST 2012

Tim Chase wrote:

> On 03/25/12 08:11, Chris Angelico wrote:
>> On Mon, Mar 26, 2012 at 12:03 AM, Tim Chase
>> <python.list at>  wrote:
>>> Granted, this can be turned into an iterator with a yield, making the
>>> issue somewhat moot:
>> No, just moving the issue to the iterator. Your iterator has exactly
>> the same structure in it.
> Yeah, it has the same structure internally, but I'm somewhat
> surprised that the DB connection object doesn't have an
> __iter__() that does something like this automatically under the
> covers.

Most of my database programs wind up having the boilerplate (not tested):

def rowsof (cursor):
    names = [x[0] for x in cursor.description]
    r = cursor.fetchone()
    while r:
        yield dict (zip (names, r))
        r = cursor.fetchone()

>> Personally, I quite like assignment-in-conditional notation. Yes, it's
>> a pretty common cause of problems; but what happened to the
>> "consenting adults" policy? Python permits operator overloading and
>> even the reassignment of builtins, both of which can cause similar
>> confusion.
> In my past years of C programming, I've accidentally omitted the
> second "=" in a comparison test numerous times, requiring me to
> track down the missing character.  When I finally catch it, it's
> obvious what the problem is, but I've come to love having Python
> yell at me contextually.
>> But, that's the choice Python's made. And being able to use the same
>> symbol for assignment and comparison does have its advantages.
> The old curmudgeon in me likes the Pascal method of using "=" for
> equality-testing, and ":=" for assignment which feels a little
> closer to mathematical use of "=".
> -tkc

More information about the Python-list mailing list