Monday, 9 September 2013

Not writing to file, even with f.close()

Not writing to file, even with f.close()

I have a file that has line numbers at the start of it. I wrote a python
script to eliminate these line numbers.
with open('file.txt','r+') as myfile:
for line in myfile:
whitespaceloc = line.find(' ')
newline = line[whitespaceloc:]
myfile.write("%s" %newline)
myfile.close()
This print's to console just fine but when I open up file.txt no changes
have occurred. The only difference is that at the end of the file there is
a new line that says "is not set"
What is going on here?

No comments:

Post a Comment