文件中使用的字符的简单报告器
repchar的Python项目详细描述
这是一个简单的命令行脚本,它创建了 给定文档中包含的字符。
用法
repchar[-h]-o输出文件名[-v][-c]infename
- 位置参数:
- 内嵌名文件名
- 可选参数:
-h, --help show this help message and exit -o OUTFILENAME, --outfile OUTFILENAME, --out OUTFILENAME Filename for report -v, --verbose Set log level to INFO. --version show program’s version number and exit -c, --comb, --combining Create special report for combining characters
Reporter类
您还可以在自己的代码中使用CharReporter类:
>>> fromrepcharimportCharReporter>>> s=u"ABCD">>> r=CharReporter()>>> r.feed(s)>>> print(r.report())chr hex count unicode A 0041 1 LATIN CAPITAL LETTER A B 0042 1 LATIN CAPITAL LETTER B C 0043 1 LATIN CAPITAL LETTER C D 0044 1 LATIN CAPITAL LETTER D
每个字母的计数存储在CharReporter.chars:
>>> r.chars{u'A': 1, u'C': 1, u'B': 1, u'D': 1}
有关组合字符的特殊信息可以在 CharReporter.combdir如果在实例化时这样说:
>>> fromrepcharimportCharReporter>>> r2=CharReporter(combining=True)>>> s=u"Caffe\u0300">>> r2.feed(s)>>> print(r2.report().encode("UTF-8"))chr hex count unicode C 0043 1 LATIN CAPITAL LETTER C a 0061 1 LATIN SMALL LETTER A e 0065 1 LATIN SMALL LETTER E f 0066 2 LATIN SMALL LETTER F ̀ 0300 1 COMBINING GRAVE ACCENT 1 with: LATIN SMALL LETTER E >>> r2.combdir{u'\u0300': {u'e': 1}}