編碼問題可能導(dǎo)致python讀取中文路徑時出錯,使python讀取中文路徑失敗,下面我們就來看一下解決方法:
解決方法一:路徑拆分單獨編碼
importos
root_path='E:\\project\\sk_man-master\\SK\\static\\sk\\new_clothes\\'+u'褲子'
forfileinos.listdir(root_path):
printfile.decode('gbk')
方法二:對全部路徑用unicode格式編碼
root_path=unicode('E:\\project\\sk_man-master\\SK\\static\\sk\\new_clothes\\褲子','utf-8')
以上內(nèi)容為大家介紹了python讀取中文路徑失敗怎么解決?希望對大家有所幫助,如果想要了解更多Python相關(guān)知識,請關(guān)注IT培訓(xùn)機(jī)構(gòu):千鋒教育。