sonderzeichen.py

"""
    sonderzeichen.py: enthält einen Filter für HTML-Sonderzeichen
"""
# kodiert Umlaute, etc. in HTML
def sonderzeichen (zeile):
    text = ''
    for i in range( len(zeile) ):
        if zeile[i] == 'ä':
            text = text + 'ä'
        elif zeile[i] == 'Ä':
            text = text + 'Ä'
        elif zeile[i] == 'ö':
            text = text + 'ö'
        elif zeile[i] == 'Ö':
            text = text + 'Ö'
        elif zeile[i] == 'ü':
            text = text + 'ü'
        elif zeile[i] == 'Ü':
            text = text + 'Ü'
        elif zeile[i] == 'ß':
            text = text + 'ß'
        elif zeile[i] == '<':
            text = text + '&lt;'
        elif zeile[i] == '>':
            text = text + '&gt;'
        elif zeile[i] == '&':
            text = text + '&amp;'
        elif zeile[i] == '"':
            text = text + '&quot;'
        else:
            text = text + zeile[i]
    return text

# ausprobieren:
testzeile = '"Immer öfter könnte ich mich ärgern '
testzeile = testzeile + 'über üble Programmierfähler & Würmer"'
print '\n\nStart . . .(sonderzeichen.py)\n'
print testzeile
print
print sonderzeichen(testzeile)
print
print '\n\nBeendet . . .(sonderzeichen.py)\n'

Fenster schließen