In order to convert a string to HTML/XML entities you can use:
”.join([‘&#%d;’ % ord(ch) for ch in text])
For example if text=’mailto’ the output would be:
‘& #109;& #97;& #105;& #108;& #116;& #111;’
This might be useful in hiding email addresses in web pages.
October 18, 2008 at 2:58 pm |
That’s not ‘localization aware’ though (try filtering some Greek text through it). I’m afraid I am not a very experienced Python programmer to help writing a version that *is* L17n-aware.