
正文
python 转换代码格式
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
import os
dirname="C:\\Users\\haier\\Desktop\\new" def walk(path):
for item in os.listdir(path):
subpath = os.path.join(path, item)
#subpath=subpath.replace('\\','\\\\')
print subpath
for i in open(subpath):
pass#print i
ffrom=open(subpath,'r')
fto=open(subpath+"",'w')
while True:
l=ffrom.readline()
if not l:
break
if 'endif' in l:
print l
l=l.replace('endif','end')
print l
elif 'endwhile' in l:
print l
l=l.replace('endwhile','end')
print l
# if '\"' in l:
# print l
# l=l.replace('\"','\'')
# print l
# print l
# tmp=l.split("\"")
#l=tmp[0]+"\'"+tmp[1]
fto.write(l)
ffrom.close()
fto.close() def dele(path):
for item in os.listdir(path):
subpath = os.path.join(path, item)
# subpath=subpath.replace('\\','\\\\') if os.path.exists(subpath+""):
ffrom=open(subpath+"",'r')
fto=open(subpath,'w')
while True:
l=ffrom.readline()
if not l:
break
fto.write(l)
ffrom.close()
fto.close()
os.remove(subpath+"") walk(dirname)
dele(dirname)








