import chardetdef CheckCode(filename): adchar=chardet.detect(filename) if adchar[‘encoding‘]==‘utf-8‘: filename=filename.decode(‘utf-8‘) else: filename=filename.decode(‘gbk‘) return filename
python 字符串编码转换
原文:http://www.cnblogs.com/tsw123/p/6027481.html