[python] [:lower:] apod.?

Alexandr Rosen alexandr.rosen na ff.cuni.cz
Neděle Leden 27 13:18:24 CET 2008


Diky! Ja to mam ve Windows XP, Python 2.5.1 trochu jinak a zda se, ze to funguje:

>>> import string, locale, re
>>> locale.setlocale(locale.LC_CTYPE, '')
'Czech_Czech Republic.1250'
>>> string.lowercase
'abcdefghijklmnopqrstuvwxyz\x9a\x9c\x9d\x9e\x9f\xb3\xb5\xb9\xba\xbe\xbf\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe'
>>> re_lower = r'[%s]' % string.lowercase
>>> re.findall(re_lower, s)
['a', '\xe1', 'b', 'c', '\xe8', 'd', '\xef', 'e', '\xec', '\xe9', 'f', 'g', 'h', 'i', '\xed', 'j',
'k', 'l', 'm', 'n', '\xf2', 'o', '\xf3', 'p', 'q', 'r', '\xf8', 's', '\x9a', 't', '\x9d', 'u',
'\xfa', '\xf9', 'v']

Bylo by fajn, kdyby to takhle slo i v utf-8.


> "Alexandr Rosen" <alexandr.rosen na ff.cuni.cz> wrote:
>> Diky moc, ale jak se s tim pracuje? Daji se ty znakove konstanty
>> pouzit v regularnich vyrazech? Jak?
>
> import string
> re_upper = ur'[%s]+' % string.uppercase
> re_lower = ur'[%s]+' % string.lowercase
>
> ale
>
>>>> import string, locale
>>>> locale.setlocale(locale.LC_CTYPE, 'cs_CZ')
> 'cs_CZ'
>>>> string.lowercase
> 'abcdefghijklmnopqrstuvwxyz'
>>>> locale.setlocale(locale.LC_CTYPE, 'de_DE')
> 'de_DE'
>>>> string.lowercase
> 'abcdefghijklmnopqrstuvwxyz\xb5\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8
> \xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb
> \xfc\xfd\xfe\xff'
>
> python 2.5.1 ymmv
> jde to nahradit dalsi prasarnou
>
> import sys
> uppercase = u''.join(unichr(i) for i in range(sys.maxunicode)
>   if unichr(i).isupper())
> lowercase = u''.join(unichr(i) for i in range(sys.maxunicode)
>   if unichr(i).islower() )



Další informace o konferenci Python