Skip to content

Instantly share code, notes, and snippets.

@tvwerkhoven
Created September 20, 2011 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tvwerkhoven/1228858 to your computer and use it in GitHub Desktop.
Save tvwerkhoven/1228858 to your computer and use it in GitHub Desktop.
pyglyph -- identify unicode glyphs
pyglyph -- identify unicode glyphs
* About
pyglyph.py can be used to decode unicode strings and identify the glyphs.
This can be useful if you want to know what exact glyph was used somewhere,
simply copy it and use it as input for pyglyph.
Pyglyph works best with python2.7 (because of argparse), but is compatible
with earlier versions.
* Usage
usage: pyglyph.py [-h] TEXT
Decode a Unicode glyph.
positional arguments:
TEXT unicode glyphs to analyze
optional arguments:
-h, --help show this help message and exit
#!/usr/bin/env python
# encoding: utf-8
"""
pyglyph.py -- Get information on (Unicode) glyphs
"""
## @file pyglyph.py
# @author Tim van Werkhoven (t.i.m.vanwerkhoven@xs4all.nl)
#
# Created by Tim van Werkhoven.
# Copyright (c) 2011 Tim van Werkhoven (t.i.m.vanwerkhoven@xs4all.nl)
#
# This file is licensed under the Creative Commons Attribution-Share Alike
# license versions 3.0 or higher, see
# http://creativecommons.org/licenses/by-sa/3.0/
# Libraries
import sys
try:
import argparse
except ImportError:
print "Please run in Python2.7 for improved usability"
except:
print "Unexpected error:", sys.exc_info()[0]
raise
import unicodedata
### Main routine
def main(*argv):
# Helper string for this function
glyph=''
try:
parser = argparse.ArgumentParser(\
description='Decode a Unicode glyph.')
# Add positional argument (filepath)
parser.add_argument('glyph', action='store', nargs='+',
metavar='TEXT', type=str, help='unicode glyphs to analyze')
args = parser.parse_args()
inputlist = args.glyph
except NameError:
if (len(argv) > 1):
inputlist = argv[1:]
pass
except:
raise
glyphs = " ".join(inputlist)
glyphlist = glyphs.decode(sys.getfilesystemencoding())
### DO STUFF HERE
for glyph in glyphlist:
if (len(glyph)):
print u"Glyph info: %s (Unicode %d, %s)" % (glyph, ord(glyph), unicodedata.name(glyph).capitalize())
# Check if we are run from commandline
if __name__ == '__main__':
sys.exit(main(*sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment