Python os.walk遍历文件夹路径过深报错怎么解决 python中的os.walk函数为什么遍历带有中文的路径时...
\u8bfb\u53d6python\u904d\u5386\u4e2d\u6587\u76ee\u5f55\u5f97\u5230\u7684\u6587\u4ef6\u8def\u5f84\u62a5\u9519\u8fd9\u662f\u56e0\u4e3a\u8def\u5f84\u91cc\u9762\u5305\u542b\u4e2d\u6587\u7684\u539f\u56e0\uff1a
linux\u7684\u7cfb\u7edf\u5b57\u7b26\u7f16\u7801\u9ed8\u8ba4\u4e3autf-8\uff0c\u800c\u8981\u641c\u7d22\u7684\u6587\u4ef6\u8def\u5f84nameFile\u662fUnicode\uff0c\u9700\u8981\u8fdb\u884c\u89e3\u7801\u6210unicode\uff0c\u56e0\u6b64\u4f5c\u5982\u4e0b\u4fee\u6539\uff1a
fout = codecs.open(nameFile.encode("utf-8") , "w" , "utf-8"
\u5f53\u7136\uff0c\u53e6\u5916\u4e00\u79cd\u65b9\u6cd5\u5c31\u662f\u4fee\u6539\u4e3a\u82f1\u6587\u7684\u8def\u5f84\uff1b
\u5173\u4e8e\u7f16\u7801\u548c\u89e3\u7801\u7684\u77e5\u8bc6\uff0c\u8bf7\u53c2\u8003\uff1ahttp://www.cnblogs.com/qiernonstop/p/3634462.html
\u6587\u4ef6\u5934\u90e8\u7684\u7f16\u7801\u683c\u5f0f\u58f0\u660e\uff0c\u53ea\u662f\u544a\u8bc9\u89e3\u91ca\u5668\uff0c\u672c\u6587\u4ef6\u662f\u4ec0\u4e48\u7f16\u7801\u683c\u5f0f\u7684\uff0c\u4e0e\u4f60\u8fd9\u4e2a\u95ee\u9898\u5e76\u65e0\u76f4\u63a5\u5173\u7cfb\u3002os.walk()\u4e2d\u5e94\u8be5\u4f20str\u8fd8\u662funicode\uff0c\u8fd9\u4e2a\u95ee\u9898\u4f60\u5e94\u8be5\u53bb\u67e5\u4e0b\u6587\u6863\uff0c\u800c\u4e0d\u662f\u9760\u731c\u3002\u8bd5\u4e00\u4e0b\u8fd9\u6837\u505a\u5427\uff1aos.walk(u'\u542b\u4e2d\u6587\u7684\u8def\u5f84'.encode('gbk'))
import sysreload(sys)
sys.setdefaultencoding('utf-8')
扩展阅读:javascript免费网站 ... python subprocess ... python shutil copy ... python手机版下载安装 ... java config ... python normalize ... python os remove ... java bigint ... python os listdir ...