Documentation, assignment in expression.

Chris Angelico rosuav at gmail.com
Sun Mar 25 10:11:48 EDT 2012


On Mon, Mar 26, 2012 at 12:48 AM, Tim Chase
<python.list at tim.thechases.com> wrote:
> 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.

Sure. That's definitely the truly Pythonic technique. If I build a C++
object that acts like an array, it's going to overload the []
dereference operator - and if I build a Python object that returns a
series of things, it's going to be an iterable.

> 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.

This is where compiler warnings come in handy. GCC will, in what I
told someone was "Perls of Wisdom mode" (with the -Wall option - yes,
it is that bad a pun), recommend clarification of the worst offenders
of this sort. And in the common case where you're comparing against a
constant, quite a few compilers will alert you to the fact that your
condition is always true/always false (eg "if (x=3) ;"). Many problems
can be solved in multiple ways; sometimes there's a clear "best way",
other times it really doesn't matter matter matter matter matter.

ChrisA



More information about the Python-list mailing list