Archive for the ‘Python’ Category

Python — Convert string to HTML/XML entities

October 18, 2008

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.


Compile Python eggs

July 28, 2006

To compile a .egg from a standard based Python package, add

from setuptools import setup

to, before the other setup/distutils imports, and then run

./ bdist_egg
This will create a .egg package in dist/ subdirectory, and can be installed with easy_install.