python读取中文路径时出错

编码问题可能导致python读取中文路径时出错

解决方法一:路径拆分单独编码

import os
    

root_path = 'E:\\project\\sk_man-master\\SK\\static\\sk\\new_clothes\\'+u'裤子'
    for file in os.listdir(root_path):
	print file.decode('gbk')

方法二:对全部路径用unicode格式编码

root_path = unicode('E:\\project\\sk_man-master\\SK\\static\\sk\\new_clothes\\裤子','utf-8')

猜你喜欢

转载自blog.csdn.net/shuzishij/article/details/82155878
今日推荐