[PYTHONMAC-SIG] German Umlauts and HTML

Robin Friedrich friedrich@pythonpros.com
Mon, 24 Nov 1997 11:43:40 -0600


If speed isn't a big concern you might try this little item...

from string import join

def latin1_escape(s):
    sl = map(None, s)
    for i in range(len(sl)):
        ordinal = ord(sl[i])
        if 160 <= ordinal <= 255:
            sl[i] = '&#%d;' % ordinal
    s_html = join(sl, '')
    return s_html

s = 'Some odd text: \321 \352 \361'
print s
print latin1_escape(s)


If you have 1.5 then I can think of a faster implementation.

Joerg Kantel wrote:

> I have written a little Python-Scripts to generate automatically HTML-pages
> from a database (FielMaker). But it's a german database and it includes
> German Umlauts. I wonder if someone has written a modul for converting
> umlauts to HTML-code. I can wirte it with a lot of if ... then ... else ...
> code by myself but I think it's more a Job for the grep-module (but I
> haven't work with grep until now). Thanks for every help (and excuse my
> poor english).

You're welcome (and your English is better than my German;-)

>
>
> J"org

--
Robin K. Friedrich     Houston, Texas
  Python Professional Services, Inc.
      friedrich@pythonpros.com
     http://www.pythonpros.com



_______________
PYTHONMAC-SIG  - SIG on Python for the Apple Macintosh

send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________