Skip to content

Instantly share code, notes, and snippets.

@mkhl
Created June 3, 2011 22:25
Show Gist options
  • Save mkhl/1007282 to your computer and use it in GitHub Desktop.
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.
#!/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