0
votes

How can I do this so that after appending when I run the code again it starts the file off fresh with only the header lines?

with open('svg5.svg','a+') as txt:
1
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)