You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Changing the locale changes string.letters -- that is expected behavior.
rupole commented on Jul 1, 2008
rupolemannequin
MannequinAuthor
More actions
It introduces high characters that cause comparisons to fail under IDLE
that succeed from the normal python prompt:
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import string
>>> u'a'in string.letters
True
IDLE 1.2.2
>>> import string
>>> u'a'in string.letters
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
u'a' in string.letters
UnicodeDecodeError: 'ascii' codec can't decode byte 0x83 in position
52: ordinal not in range(128)
Or am I misunderstanding how the locale works with string comparisons ?
Well, that wouldn't be different if you had set the locale in your
prompt. In short, u'a' in string.letters can never work with any
string.letters except the default, English-only one, and therefore is wrong.
loewis commented on Jul 1, 2008
loewismannequin
Mannequin
More actions
As Georg says: you shouldn't be mixing Unicode objects and string
objects. It's perfectly valid for string.letters to contain non-ASCII
bytes, and it's no surprise that this fails for you. string.letters
indeed *does* contain only letters.
In any case, testing for letter-ness by using "in string.letters" is not
a good idea, as it involves a linear search. I recommend to use
Activity
rupole commentedon Jun 30, 2008
The problem seems to stem from this line in IOBinding.py:
locale.setlocale(locale.LC_CTYPE, "")
loewis commentedon Jun 30, 2008
Why do you think string.letters gets corrupted? AFAICT, it's still correct.
birkenfeld commentedon Jun 30, 2008
Changing the locale changes string.letters -- that is expected behavior.
rupole commentedon Jul 1, 2008
It introduces high characters that cause comparisons to fail under IDLE
that succeed from the normal python prompt:
Or am I misunderstanding how the locale works with string comparisons ?
birkenfeld commentedon Jul 1, 2008
Well, that wouldn't be different if you had set the locale in your
prompt. In short,
u'a' in string.letterscan never work with anystring.letters except the default, English-only one, and therefore is wrong.
loewis commentedon Jul 1, 2008
As Georg says: you shouldn't be mixing Unicode objects and string
objects. It's perfectly valid for string.letters to contain non-ASCII
bytes, and it's no surprise that this fails for you. string.letters
indeed *does* contain only letters.
In any case, testing for letter-ness by using "in string.letters" is not
a good idea, as it involves a linear search. I recommend to use
u"a".isalpha()
instead