Created
June 3, 2011 22:25
-
-
Save mkhl/1007282 to your computer and use it in GitHub Desktop.
Inspired by something Peter Hosey did. Converts text to small caps unicode glyphs.
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 | |
import fileinput, unicodedata | |
def convert_char(char): | |
try: | |
name = unicodedata.name(char) | |
name = name.replace('LATIN SMALL LETTER', 'LATIN LETTER SMALL CAPITAL') | |
return unicodedata.lookup(name) | |
except KeyError: | |
pass | |
except ValueError: | |
pass | |
return char | |
def convert_line(line): | |
caps = [] | |
for char in list(line): | |
caps.append(convert_char(char)) | |
return u''.join(caps) | |
if __name__ == '__main__': | |
for line in fileinput.input(): | |
caps = convert_line(line.rstrip(u'\n')) | |
print caps.encode('utf8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment