[Tutor] Re: printing special characters

Christopher Smith csmith@blakeschool.org
Tue, 25 Sep 2001 10:32:00 -0500


wilson@visi.com writes:
>On Tue, 25 Sep 2001, Christopher Smith wrote:
>
>> I'm working on 2 solutions: 1) find a common font to both systems (lik=
e
>> symbol or chemsyn for the pc/mac) 2) convert what I need to be seen to
>> html and view it on any system using a browser.  For the latter purpos=
e
>I
>> have been testing TtH by Andrew Treverrow, author of OzTeX for the mac.
>
>I'm just trying to get the symbols to print for my students' next
>project, a
>simple temp converter. (see
>http://www.isd197.org/sibley/cs/icp/assignments/temp_html)

OK, that's easier.

-find out the code to the character on all target systems
-when running the script, determine your system and=20
 select the appropriate code

On the mac it's code 161 (\xa1).

>>> import sys
>>> sys.platform #find out what you are running on
'mac'
>>> ord('=B0')  #if you can type it, you can find the decimal code
161
>>> chr(161)  #repr will give the hex code
'\xa1'
>>> print chr(161) #str will give the proper symbol
=B0                  # on the mac I see a degree symbol=20
>>> deg=3D'\xa1'     # assign the hex code to a variable
>>> print deg+'F'  # concatenate at will
=B0F                 # here I see degree symbol followed by F

Note:  I checked the extended latin-1 unicode table
http://www.unicode.org/charts/PDF/U0080.pdf
and it lists the degree as \xb0 and \xa1 as the inverted
exclamation mark, so apparently I am looking at the wrong
unicode table or else the mac is not using latin-1 translation.

Hmmm...Skip just posted something about someone else's
problem with a rogue character.  Maybe that's useful for
us here:

>>> d=3Du'\N{DEGREE SIGN}'  #tell u the name of the character
>>> d

u'\xb0'
>>> d.encode('mac-latin2') #encode it for the system

'\xa1'
>>>=20

SO...look up the name of the symbol that you want in the unicode table
(in this case the name is DEGREE SIGN) and use the unicode string feature
to give you the code which you then can encode into the appropriate
hex code with the encode() operator.  Of course, you still need to find
out what system you are on since I doubt you will want to use mac-latin
for windows.

HTH,

/c