如何从文件中读取并将每个参数写入不同的文件。但每条线都必须颠倒和居中。 clarity == VS1
部分
#write mirror file
运行此代码时出现的错误是
#some variables
Lines = 0
ShortestLine = 80
Longestline = 0
Emptylines = 0
width = 80
Fillchar = " "
#open files
file = "radishsurvey.txt"
p = open (file,"r")
q = open ("mirroredfile.txt","w")
#loop to count lines and length
for line in p:
Lines +=1
length = len(line)
if length < ShortestLine:
ShortestLine = length
if length > Longestline:
Longestline = length
if length == 0:
Emptylines += 1
#write mirror file
q.write("{0:}\n".format(p.reversedString(line[-2::-1]).center(80)))
q.close()
p.close()
答案 0 :(得分:0)
“W”先清理你的文件,然后写下你的新数据!你应该附加你的文件,用“a”来保存以前的数据......