Hello. I am a complete newbit to Python. I am trying to read a text file (which is actually an svg file) and add a line to the text file. I would also like to remove certain text from the file. I am trying to edit some of the tags in the file. Here is the code that I have so far. I have only figured out how to read the file and append to it. But I don't know how to do actual edits.
def main(): f = open("F01.svg", "r") if f.mode == 'r': fl = f.readlines() for x in fl: if x.find("</g>") > -1: print (x) if __name__ == "__main__": main()
This prints out the contents of the entire file. But now I need to find the </g> tag at the end and add another one either right before it or right after it. So I'm guessing I need a way to track all the </g> tags in the file and then after the last one add aonther one. I also think I need to know how I can also find a tag and add attributes to them.
thanks in advance.