发布时间:2019-09-08 09:13:28编辑:auto阅读(1836)
python中的中文路径解决:
注:
1、sys.setdefaultencoding('utf-8')将python默认encode改为utf-8
2、p.write(s.encode('utf-8')+"\n")写入时再encode('utf-8')
#!/usr/bin/python
#coding=utf-8
import os
import shutil
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
dir="/root/python"
for root,dirs,files in os.walk(dir):
for f in files:
if f == "bb.txt":
s = os.path.dirname(os.path.join(root,f))
p = open('/root/python/logs/py.log','a')
p.write(s+"\n")
p.close()
c = open('/root/python/logs/py.log','r')
for i in c.readlines():
shutil.rmtree(i.strip())
:wq
上一篇: Python HTTP POST方法一例
下一篇: 【python学习】windows下安装
47863
46424
37314
34760
29332
25990
24945
19967
19564
18050
5806°
6433°
5947°
5975°
7080°
5926°
5963°
6456°
6418°
7798°