Documentation, assignment in expression.

Sun Mar 25 17:17:10 CEST 2012

On 3/25/2012 16:11, Chris Angelico wrote:
> On Mon, Mar 26, 2012 at 12:48 AM, Tim Chase
> <python.list at>  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.

STL's containers are *heavily* based on iterators. There are forward 
iterators, bidirectional iterators and even random access iterators.
You can also write (in C++11)
   int my_array[5] = {1, 2, 3, 4, 5};
   for (int &x : my_array)
     x *= 2;
It works with every container or object which returns iterators through 
begin() and end().
Note the ampersand which means "get the reference of".


More information about the Python-list mailing list