[Tutor] special character ( ñ )

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Mon Dec 1 16:47:50 EST 2003



On Sat, 29 Nov 2003, Michael Lange wrote:

> On Fri, 28 Nov 2003 13:56:17 -0500 (EST)
> clickron at webtv.net (Ron A) wrote:
>
> > I have python 2.2.2.  Is there an easy way to type =F1 (n with tilde) o=
r
> > other special characters?.
> >
> I am afraid that I'm not an encoding expert, but I guess you have the sam=
e problems
> as I have with german special characters.
> In this case it depends on *where* you want to print it:
> In IDLE(python 2.2.3):
>
> >>> print '=E4'
> UnicodeError: ASCII encoding error: ordinal not in range(128)


Hello!


It sounds like you're trying to use ISO-8859-1 encoding to display
accented characters on your system.


If your terminal supports it, then you can use:

    ftp://unicode.org/Public/MAPPINGS/ISO8859/8859-1.TXT

to find out the right hexadecimal constants.  For example, the tilde 'n'
maps to the entry:

"""
0xF1=090x00F1=09#=09LATIN SMALL LETTER N WITH TILDE
"""


So if your terminal display natively supports ISO-8859-1, then something
like:

###
print '\xf1'
###

should do the trick.



However, if you're using a terminal that natively supports a different
encoding system, then you need to do something slightly different.
Apple's Terminal application, for example, natively uses UTF8.


So you might need to do something like:

###
print '\xf1'.decode('iso8859-1').encode('utf8')
###

to see a tilde 'n' on MacOSX's Terminal.




> If you just suffer from IDLE's limitations try idlefork :
>
> < http://idlefork.sourceforge.net >
>
> It's IDLE with a few extra features; as far as I know it replaces the
> "original" IDLE since python 2.3 .


I believe IDLE supports Unicode now, so try the second snippet example and
see if you get that tilde 'n' from there.



Good luck to you!




More information about the Tutor mailing list