string.printable unchanged by locale

Magnus Lyckå magnus at thinkware.se
Fri Nov 1 17:38:26 EST 2002


According to the Library Reference, string.printable is a combination
of digits, letters, punctuation, and whitespace. But it's not affected
by locale settings, as can be seen below. There are also symbols such
as the Euro symbol etc, that are definitely printable, that aren't
included in any of the categories mentioned above.

It's a bit boring that there is such an entity as string.printable,
and it's not fully useful for determining whether a keypress will
print something or not.

Why do I have to do something like:

if char in string.printable + string.letters +\
'\x80\x82\x84\x85\x86\x87\x88\x89\x8b\x91\x92\x93\x94\x95'+\'
'\x96\x97\x98\x99\x9b\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9'+\
'\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7'+\
'\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xd7\xf7':

Is this intentional or a bug? Now that we have ascii_letters and
letters, shouldn't this be ascii_printable, and printable include
all locale letters, and possibly other symbols such as currency
symbols, half, section etc that appear on the normal keyboards in
the locales.

Python 2.2.1 (#34, Sep 27 2002, 18:37:42) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> import string
 >>> len(string.letters)
52
 >>> len(string.printable)
100
 >>> import locale
 >>> locale.setlocale(locale.LC_ALL, '')
'Swedish_Sweden.1252'
 >>> len(string.letters)
122
 >>> len(string.printable)
100




More information about the Python-list mailing list