[Python-Dev] len(chr(i)) = 2? (original) (raw)

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Nov 25 04:19:33 CET 2010


On 25/11/10 06:37, Alexander Belopolsky wrote:

I don't think there is a recipe on how to fix legacy character-by-character processing loop such as

for c in string: ... to make it iterate over code points consistently in wide and narrow builds.

A couple of possibilities:

  1. Make things so that 'for c in string' does actually iterate over characters rather than code units. This could break existing code, though.

  2. Provide some things like

    for c in string.chars(): ...

    for c in string.graphemes(): ...

where chars() and graphemes() return appropriate iterators. (Or possibly iterable views, but that would raise the expectation that the views could also be randomly indexed by char or grapheme, which we probably wouldn't want to support.)

-- Greg



More information about the Python-Dev mailing list