0

How do I read from a file and write every sentenence to a different file. But every line has to be reversed and centered. Something seems to be wrong with the #write mirror file part

#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()

The error i get when running this code is

line 40, in <module>
    q.write("{0:}\n".format(p.reversedString(line[-2::-1]).center(80)))
AttributeError: '_io.TextIOWrapper' object has no attribute 'reversedString'

1 Answers1

0

"W" clean your file first, then write your new data! you should append your file, use "a" for save your previous data ...

DRPK
  • 2,023
  • 1
  • 14
  • 27
  • I know this already. But this problem is about the error I get,: AttributeError: '_io.TextIOWrapper' object has no attribute 'reversedString – user8779857 Oct 22 '17 at 12:33