Alphabetics respect to a given locale

Emile van Sebille emile at fenx.com
Sat Apr 2 01:16:33 CEST 2011


On 4/1/2011 1:55 PM candide said...
> How to retrieve the list of all characters defined as alphabetic for the
> current locale ?

I think this is supposed to work, but not for whatever reason for me 
when I try to test after changing my locale (but I think that's a centos 
thing)...

import locale
locale.setlocale(locale.LC_ALL,'')
import string
print string.lowercase

I don't see where else this might be for python.

However, you can test if something is alpha:

 >>> val = u'caf' u'\xE9'
 >>> val.isalpha()
True
 >>>

... and check its unicode category

 >>> import unicodedata
 >>> unicodedata.category(u'a')
'Ll' # Letter - lower case
 >>> unicodedata.category(u'A')
'Lu' # Letter - upper case
 >>> unicodedata.category(u'1')
'Nd' # Number - decimal?
 >>> unicodedata.category(u'\x01')
'Cc' #


HTH,

Emile




More information about the Python-list mailing list