如何在替換後保留文件結構。python在每行末尾添加新行
# -*- coding: cp1252 -*-
import os
import os.path
import sys
import fileinput
path="C:\\Search_replace" # insert the path to the directory of interest
#os.path.exists(path)
#raise SystemExit
Abspath=os.path.abspath(path)
print(Abspath)
dirList=os.listdir(path)
print ('seaching in',os.path.abspath(path))
for fname in dirList:
if fname.endswith('.txt') or fname.endswith('.srt'):
#print fname
full_path=Abspath+"\\"+fname
print full_path
for line in fileinput.FileInput(full_path,inplace=1):
line = line.replace("þ","t")
line=line.replace("ª","S")
line=line.replace("º","s")
print line
print "done"
Joey:嗯... 。 什麼? – rossipedia 2011-03-03 06:45:48