Created
November 10, 2009 09:01
-
-
Save yono/230752 to your computer and use it in GitHub Desktop.
pykf を使いやすくするためのラッパー
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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