My aim is to read line from the file , strip the blank spaces at the end of it and write back into the same file. I have tried the following code:
with open(filename, 'r+') as f:
for i in f:
f.write(i.rstrip()+"
")
This seems to write at the end of the file, keeping initial data in the file intact . I know that using f.seek(0)
would take the pointer back to start of the file , which I am assuming would be somehow required for this solution.
Can you please advise if there is different approach for this or am I on the right patch just need to add more logic into the code?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…