[Tutor] Using special characters in Python

Ole Jensen learning.python@dbmail.dk
Fri Feb 21 13:09:10 2003


This is a multi-part message in MIME format.

------=_NextPart_000_0032_01C2D9DC.8E1B9500
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Ive digging a little deeper with the problem...

as from the unicode.org page i've found out that the =E5 is written like =
this: "00E5" (without the qoutes) in unicode, BUT when trying to do =
create a string to that, a la:=20
http://www.python.org/doc/2.2p1/ref/strings.html

>>> s =3D "u\00E5"
>>> print s
u

and doing this with other unicode values also returns a "u" so i guess =
something is not as it should...

annother thing I discovered with some result was the unichr() - =
function(found at http://www.python.org/doc/2.2p1/ref/types.html#l2h-63 =
under unicode), which however doesn't do exactly what i'd expect:
from http://www.unicode.org/charts/PDF/U0000.pdf:

letter   |  unicode
------------------------
   e          0065

when trying to out this into the unicode function:

>>> e =3D unichr(0065)
>>> e
u'5'
>>> print e
5

as you can see I didn't quite get the result I wanted. could it be that =
the unicode function used in python doesn't use the unicode exactly as =
it should??? or am I just doing it wrong?

again if you know of any material on this subject, don't be shy
Ol=E9
ole_jensen@dbmail.dk
------=_NextPart_000_0032_01C2D9DC.8E1B9500
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1141" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Ive digging a little deeper with the=20
problem...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>as from the unicode.org page i've found =
out that=20
the =E5 is written like this: "00E5" (without the qoutes) in unicode, =
BUT when=20
trying to do create a string to that, a la: </FONT></DIV>
<DIV><FONT face=3DArial size=3D2><A=20
href=3D"http://www.python.org/doc/2.2p1/ref/strings.html">http://www.pyth=
on.org/doc/2.2p1/ref/strings.html</A></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&gt;&gt;&gt; s =3D =
"u\00E5"</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&gt;&gt;&gt; print s</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>u</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>and doing this with other unicode =
values also=20
returns a "u" so i guess something is not as it should...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>annother thing I discovered with some =
result was=20
the unichr() - function(found at <A=20
href=3D"http://www.python.org/doc/2.2p1/ref/types.html#l2h-63">http://www=
.python.org/doc/2.2p1/ref/types.html#l2h-63</A>&nbsp;under=20
unicode), which however doesn't do exactly what i'd expect:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>from <A=20
href=3D"http://www.unicode.org/charts/PDF/U0000.pdf">http://www.unicode.o=
rg/charts/PDF/U0000.pdf</A>:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>letter&nbsp;&nbsp; | =
&nbsp;unicode</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>------------------------</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;=20
e&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0065</FONT><=
/DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>when trying to out this into the =
unicode=20
function:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&gt;&gt;&gt; e =3D =
unichr(0065)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&gt;&gt;&gt; e</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>u'5'</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&gt;&gt;&gt;&nbsp;print e</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>5</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>as you can see I didn't quite get the =
result I=20
wanted. could it be that the unicode function used in =
python&nbsp;doesn't use=20
the unicode exactly as it should??? or am I just doing it =
wrong?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>again if you know of any material on =
this subject,=20
don't be shy</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Ol=E9<BR><A=20
href=3D"mailto:ole_jensen@dbmail.dk">ole_jensen@dbmail.dk</A></FONT></DIV=
></BODY></HTML>

------=_NextPart_000_0032_01C2D9DC.8E1B9500--