网站搭建哪家好,国外好的电商网站有哪些,网站域名更改了怎么换,网站建设公司3lue为什么80%的码农都做不了架构师#xff1f; 养成使用utf8格式的习惯#xff0c;但是不能保证所有的代码都是utf8格式#xff0c;所以这里提供三个函数 getCoding tran2UTF8 tran2GBK #xff0c;分别是查看编码格式#xff0c;转换为utf8#xff0c;gbk格… 为什么80%的码农都做不了架构师 养成使用utf8格式的习惯但是不能保证所有的代码都是utf8格式所以这里提供三个函数 getCoding tran2UTF8 tran2GBK 分别是查看编码格式转换为utf8gbk格式加入你的输出是乱码可以重定向出来使用notepad查看调整编码直到看到的中文正常比如以ANSI编码时发现中文显式正常说明输出是ansi格式而中文是不可能用ansi码表示的所以判断其格式是unicode def getCoding(strInput):获取编码格式if isinstance(strInput, unicode):return unicodetry:strInput.decode(utf8)return utf8except:passtry:strInput.decode(gbk)return gbkexcept:passdef tran2UTF8(strInput):转化为utf8格式strCodingFmt getCoding(strInput)if strCodingFmt utf8:return strInputelif strCodingFmt unicode:return strInput.encode(utf8)elif strCodingFmt gbk:return strInput.decode(gbk).encode(utf8)def tran2GBK(strInput):转化为gbk格式strCodingFmt getCoding(strInput)if strCodingFmt gbk:return strInputelif strCodingFmt unicode:return strInput.encode(gbk)elif strCodingFmt utf8:return strInput.decode(utf8).encode(gbk) 相关资料http://my.oschina.net/u/993130/blog/199214 转载于:https://my.oschina.net/sanpeterguo/blog/209134