PEP368 and pixeliterators

Joachim Strömbergson Joachim at Strombergson.com
Thu Jul 2 04:32:04 EDT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Aloha!

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

http://www.python.org/dev/peps/pep-0368/

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
http://www.strombergson.com/kryptoblog
========================================================================
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpMcIQACgkQZoPr8HT30QFkcgCgzxb9JS2l87B/nkpf05FLDjY5
RPQAni2yPxKjCd4lM/qMBNhjp8HHg/PZ
=9gB/
-----END PGP SIGNATURE-----



More information about the Python-list mailing list