def rep_split(infile,spliter,repter): with open(infile,'r') as sp_file: for line in sp_file: newline=line[::-1].replace(spliter,repter,1)[::-1] print(newline) #open('out.txt','a').writelines(outline)
>>> for ln in content.splitlines(): ... x = ln.split(spliter) ... print spliter.join(x[:-1]), x[-1] ... a\b\ccc ddd xxx\y zzz q w >>>
第3个回答 2013-05-30
def myreplace(s):
index = s.rfind("\\") if index != -1: s = s[:index]+" "+s[index+1:] return s text = open("yourfilename","r") content = text.readlines() text.close() for name in content: (four space here)print myreplace(name)