[python] [:lower:] apod.?

Alexandr Rosen alexandr.rosen na ff.cuni.cz
Nedìle Leden 27 14:13:21 CET 2008


Zapomnel jsem rict, co bylo to "s":

>>> s = "aábcèdïeìéfghiíjklmnòoópqrøs¹t»uúùvABCÈDÏEÉÌFGHIÍJKLMNOÓPQRØS©T«UÚÙVWXYÝZ"
>>> s
'a\xe1bc\xe8d\xefe\xec\xe9fghi\xedjklmn\xf2o\xf3pqr\xf8s\x9at\x9du\xfa\xf9vABC\xc8D\xcfE\xc9\xccFGHI\xcdJKLMNO\xd3PQR\xd8S\x8aT\x8dU\xda\xd9VWXY\xddZ'
>>>

Jeste s tim re_lower, tohle nefunguje (re_lower uz je string):

>>> re_lower = r'[%s]' % string.lowercase
>>> re.sub(r'\n(re_lower)',r'\1',x)

Existuje nejaky lepsi zpusob, jak to obejit, nez tohle: (?)

>>> string = r'\n' + '('
>>> string = string + re_lower
>>> string = string + ')'
>>> re.sub(string,r'\1',x)

>>> string
'\\n([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])'


---

> 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.



Dal¹í informace o konferenci Python