Skip to content

Instantly share code, notes, and snippets.

@yono
Created November 10, 2009 09:01
Show Gist options
  • Save yono/230752 to your computer and use it in GitHub Desktop.
Save yono/230752 to your computer and use it in GitHub Desktop.
pykf を使いやすくするためのラッパー
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
pykf_wrapper.py
pykf を使いやすくするためのラッパー
使い方
import pykf_wrapper
encode = pykf_wrapper.guess('文字コード判定')
print encode
"""
import pykf
pykf.setstrict(False)
ENC = {
pykf.UNKNOWN:None, pykf.ASCII:'ASCII',
pykf.SJIS:'SHIFT_JIS',pykf.EUC:'EUC-JP',
pykf.JIS:'ISO-2022-JP',pykf.UTF8:'UTF-8',
pykf.UTF16:'utf-16',pykf.UTF16_BE:'utf-16_be',
pykf.ERROR:None
}
def guess(text):
g = pykf.guess(text)
return ENC[g]
if __name__ == '__main__':
encode = guess('文字コード判定')
print encode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment