Created
March 2, 2012 18:53
-
-
Save amundo/1960359 to your computer and use it in GitHub Desktop.
letters.py - command line tool to look up the name of Unicode characters in a text
This file contains hidden or 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
| #!/usr/bin/env python | |
| """ | |
| pathall@gmail.com | |
| Do Whatever the Fuck You Want To License | |
| http://sam.zoy.org/wtfpl/ | |
| letters - cat some UTF-8 text to this script, and | |
| it will output the unicode name of the characters in the text, if | |
| there is one. | |
| """ | |
| import sys | |
| from unicodedata import name | |
| import codecs | |
| sys.stdout = codecs.getwriter('utf-8')(sys.stdout) | |
| content = sys.stdin.read().strip() | |
| text = content.decode('utf-8') | |
| for letter in text: | |
| try: | |
| uniname = name(letter) | |
| except ValueError: | |
| continue | |
| print letter, uniname, "(U+%.4X)" % ord(letter), 'u"\\u' + "%.4X" % ord(letter) + '"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment