File I/O

jimburton jimburton1 at
Fri Sep 29 13:18:21 CEST 2006

Kirt wrote:
> i dont wanna parse the xml file..
> Just open the file as:
> f=open('test.xml','a')
> and append a line "<Body2>abc</Body2>" before  tag </Top>

Use a regex to split the contents and insert new stuff, eg

import re
prog = prog = re.compile('^(.*)(</Top>)', re.DOTALL)
m =

then is everything before </Top> and is </Top>.
Put them together with your new tag and write it back to the file

More information about the Python-list mailing list