创建国际网站,新建网站推广给企业,wordpress 多语言 主题,wordpress.模板windows使用gbx(gb2312,gbk,gb18030我也不知道是哪个)对文件名及文件路径进行编码保存。打开文件的函数中使用诸如open(filename.encode(‘gbk‘))可以很好的解决。#coding:utf8if __name__ ‘__main__‘:srcfile rD:/测试路径/测试文件.txtf open(srcfile.deco…windows使用gbx(gb2312,gbk,gb18030我也不知道是哪个)对文件名及文件路径进行编码保存。打开文件的函数中使用诸如open(filename.encode(‘gbk‘))可以很好的解决。#coding:utf8if __name__ ‘__main__‘:srcfile rD:/测试路径/测试文件.txtf open(srcfile.decode(‘utf8‘).encode(‘gbk‘))for text in f.readlines():print text.decode(‘gbk‘)f.close()或者#coding:utf8if __name__ ‘__main__‘:srcfile uD:/测试路径/测试文件.txtf open(srcfile.encode(‘gbk‘))for text in f.readlines():print text.decode(‘gbk‘)f.close() 上述两种方法均可。另外不要下面被这句话干扰print text.decode(‘gbk‘) 它只表示文件内容是用gbk编码的。更多内容可见http://my.oschina.net/iuranus/blog/262914补充说明这里这样写也是可以打开的srcfile uD:/测试路径/测试文件.txtf open(srcfile) 但是在使用opencv库时cv2.imread(srcfile)srcfile必须以gbk编码(srcfile.encode(‘gbk‘))才能打开,同时要注意是unix风格的‘/‘而不是‘\‘。