编码问题可能导致python读取中文路径时出错,使python读取中文路径失败,下面我们就来看一下解决方法:
解决方法一:路径拆分单独编码
import os root_path = 'E:projectsk_man-masterSKstaticsk ew_clothes'+u'裤子' for file in os.listdir(root_path): print file.decode('gbk')
www#gaodaima.com来源gaodai#ma#com搞*!代#%^码$网搞代码
方法二:对全部路径用unicode格式编码
root_path = unicode('E:projectsk_man-masterSKstaticsk ew_clothes裤子','utf-8')
更多Python知识请关注搞代码网
来源:搞代码网:原文地址:https://www.gaodaima.com