Python has always been shipped with a cgi module to escape different characters, but this has limitations. Starting with Python 3.2, the HTML module curbs these shortcomings. HTML parsing and entities are achieved using different modules in Python 2 and 3, which makes compatibility even harder to achieve. This chapter describes ways of implementing HTML escaping, and parsing that work in both Python 2 and 3.
HTML Escaping
Python has always been shipped with a cgi module with an escape() function to escape different characters in versions prior to 3.2. For example, the following script ...