Created
November 18, 2011 16:11
-
-
Save ifduyue/1376898 to your computer and use it in GitHub Desktop.
mb_code.py
This file contains 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
def mb_code(string, coding="utf-8"): | |
if isinstance(string, unicode): | |
return string.encode(coding) | |
for c in ('utf-8', 'gb2312', 'gbk', 'gb18030', 'big5'): | |
try: | |
return string.decode(c).encode(coding) | |
except: pass | |
return string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment