On Jul 13, 6:07 am, Jyotirmoy Bhattacharya <[EMAIL PROTECTED]> wrote: > On Jul 13, 5:05 am, [EMAIL PROTECTED] wrote: > > > In Idle when I do print 'รก'.isalpha() I get True. When I make and > > execute a script file with the same code I get False. > > > Why do I have diferent answers ? > > Non-ASCII characters in ordinary (8-bit) strings have all kinds of > strangeness. First, the answer of isalpha() and friends depends on the > current locale. By default, Python uses the "C" locale where the > alphabetic characters are a-zA-z only. To set the locale to whatever > is the OS setting for the current user, put this near the beginning of > your script: > > import locale > locale.setlocale(locale.LC_ALL,'') > > Apparently IDLE does this for you. Hence the discrepancy you noted. > > Second, there is the matter of encoding. String literals like the one > you used in your example are stored in whatever encoding your text > editor chose to store your program in. If it doesn't match the > encoding using by the current locale, once again the program fails. > > As I see it, the only way to properly handle characters outside the > ASCII set is to use Unicode strings.
Jyotirmoy, You are right. Thank you for your information. I will follow your advice but it gets me into another problem with string.maketrans/translate that I can't solve. -- http://mail.python.org/mailman/listinfo/python-list