PEP368 and pixeliterators

Joachim Strömbergson Joachim at
Thu Jul 2 10:32:04 CEST 2009

Hash: SHA1


I just read the PEP368 and really liked the proposed idea, sound like a
great battery addition to include in the std lib:

One question/idea though: The proposed iterator will iterate over all
pixels in a line, but only one line. The example code looks like this:

# iterate over an image
for line in rgb_image:
    for pixel in line:
        # swap red and blue, and set green to 0
        pixel.value = pixel.b, 0, pixel.r

But, wouldn't it be more Pythonic and simpler to have an iterator that
iterates over all pixels in an image? Starting with upper left corner
and moving left-right and (line by line) to lower right. This would
change the code above to:

for pixel in rgb_image:
    # swap red and blue, and set green to 0
    pixel.value = pixel.b, 0, pixel.r

The idea I'm having is that fundamentally the image is made up of a 2D
array of pixels, not rows of pixels. And having the iterator focus on
pixels instead make then more sense, no?

Or if possible have two iterators.

Otherwise, big thumbs up for PEP 368 as well as having PEP:s for driving
the language development process in an orderly and well documented way.

- --
Med vänlig hälsning, Yours

Joachim Strömbergson - Alltid i harmonisk svängning.
Kryptoblog - IT-säkerhet på svenska
Version: GnuPG v1.4.8 (Darwin)
Comment: Using GnuPG with Mozilla -


More information about the Python-list mailing list