1 unescape
try:
from HTMLParser import HTMLParser # Python2
except ImportError:
from html.parser import HTMLParser # Python3
html_parser = HTMLParser()
s = '1<2'
print(html_parser.unescape(s))
# 1<2
2 escape
import cgi
s = '1<2'
print(cgi.escape(s))
# 1<2