You can't. You'll have to open it as 'r', read the lines you want to keep, then open it as 'w' and start over.
- Tim Roberts
1 Answers
0
votes
you can either append to everything or delete the content.
to keep a spefic string you can have a const like
HEADER = "this is my nice looking header"
with open(filepath,'w') as outfile:
outffile.write(HEADER)
outfile.write(whatever you want)
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more
'r'
, read the lines you want to keep, then open it as'w'
and start over. - Tim Roberts