Skip to content

Instantly share code, notes, and snippets.

@asus4
Created March 12, 2012 08:52
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 asus4/2020785 to your computer and use it in GitHub Desktop.
Save asus4/2020785 to your computer and use it in GitHub Desktop.
Export unique char from unicode text file. for Unity
#!/usr/bin/python
# coding: utf-8
import codecs,sys
"""
convert text to uniq characters
for Unity
ex:
python uniq_char.py in.txt out_uniq.txt
"""
argvs = sys.argv
argc = len(argvs)
# check argvs
if (argc != 3):
print 'Usage: # python %s in_file out_file' % argvs[0]
quit()
# open file
f = codecs.open(argvs[1], 'r', 'utf8')
txt = f.read()
f.close()
# sort
txt = sorted(set(txt), key=txt.index)
out = u""
for t in txt:
out += t
print "-------sorted-------"
print out
# write to file
fout = codecs.open(argvs[2], 'w', 'utf8')
fout.write(out)
fout.close()
@asus4
Copy link
Author

asus4 commented Mar 12, 2012

README

python uniq_char.py in_file.txt out_file.txt

日本語フォントをGlyphDesignerなどから作成するときに、使う文章から文字の重複を削除し、
指定の文章内から使っている文字のみを書きだすスクリプトです。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment