Last active
January 23, 2017 06:46
-
-
Save hackjutsu/211179a4846abab9178a3b85cfb84ace to your computer and use it in GitHub Desktop.
[HTML encoding/decoding via Python standard library] Reference: http://stackoverflow.com/a/7088472
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HTML Encoding | |
try: | |
from html import escape # python 3.x | |
except ImportError: | |
from cgi import escape # python 2.x | |
print(escape("<")) | |
# HTML Decoding | |
try: | |
from html import unescape # python 3.4+ | |
except ImportError: | |
try: | |
from html.parser import HTMLParser # python 3.x (<3.4) | |
except ImportError: | |
from HTMLParser import HTMLParser # python 2.x | |
unescape = HTMLParser().unescape | |
print(unescape(">")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment