On Feb 4, 4:26 pm, DenesL <[email protected]> wrote:
> You need to lookup each character that is not in the x00-xFF range in
> a table:
that should have read: is not in the x00-x7F range
Anyway, I gave this some thought and it all depends on how you type in
the characters.
For example in Windows, to get "LATIN SMALL LETTER A WITH ACUTE" up on
the screen I would type Alt160 or Alt0225 and I end up with '\xa0' in
both cases, both wrong.
So what can you do?
1) As previously said, type '\xc3\xa1' (the utf8 code for á).
2) Use a function. Note that in this case the function has to be typed
in and not copy-pasted, so that you get the proper code when you type
in the source.
Sample function using string:
def u8(s):
import string
# translation table to get the proper unicode char
t=string.maketrans('áéíóú','\xe1\xe9\xed\xf3\xfa\xf1\xd1\xbf\xa1')
return
string.translate(s,t).decode('unicode_escape').encode('utf-8')
Sample function using dictionary:
def u8(s):
d={'á':'\xc3\xa1',
'é':'\xc3\xa9',
'í':'\xc3\xad',
'ó':'\xc3\xb3',
'ú':'\xc3\xba'}
return ''.join([d[x] if x in d.keys() else x for x in s])
# note that the if statement above requires python 2.5 but it can be
rewritten for previous versions.
and then just type away:
IS_IN_SET( [ u8('adiós'), ... ] )
Denes.
--
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en.