[Edu-sig] Hello Greece (plus greek xhtml)

Kirby Urner pdx4d@teleport.com
Tue, 19 Jun 2001 20:52:54 -0700


Greetings to subscribers in Greece!

That *is* good news.  Python is certainly a fine language and
an excellent one for teaching programming, as it gives you
many of the key concepts relatively painlessly.  Your skills
are transferrable to other, more difficult languages.

Administrators who "haven't heard of Python" and so don't
consider allowing it as a teaching language in their schools
are really missing the boat!

By the way, just recently I was playing around with generating
an xhtml web page listing greek characters, encoding in UTF-8,
which the most recent browsers will decode as an option.

The module below will generate either latin.html or greek.html
from the command line.

Kirby

     import unicodedata
     import codecs

     """
     Chapter 2:  Cardinality
     """

     xhtmldoc = """
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     <html xmlns="http://www.w3.org/1999/xhtml" lang="UTF-8">
     """

     def greek(filename="greek.html",
                  title="Greek Characters",
                  urange=(0x384,0x3ce)):
         "List some Greek characters in xhtml lang=utf-8 format"
         mkxhtml(filename,title,urange)

     def latin(filename="latin.html",
                  title="Latin Characters",
                  urange=(0x41,0x7a)):
         "List some Latin characters in xhtml lang=utf-8 format"
         mkxhtml(filename,title,urange)

     def mkxhtml(filename,title,urange):
         "Generate xhtml filename for unicode urange (tuple)"
         f = codecs.open(filename, 'w','utf-8')
         f.write(xhtmldoc)
         f.write("<header><title>"+title+"</title></header>")
         f.write("<body><pre>")
         f.writelines(listnames(urange[0],urange[1]))
         f.write("</pre></body></html>")
         f.close()

     def listnames(low,high):
         """Return list of unicode objects:
         hex, unicode, name for low/high range"""
         lines = []
         for i in range(low,high+1):
             try:
                 lines.append(
                     "0"+hex(i)[2:]+" "
                     + unichr(i)
                     + " "+unicodedata.name(unichr(i))
                     + "\n")
             except ValueError: pass
         return lines