I have an xml file with point coordinate like this
<vertex x="15" y="15.2"/>
I would like to scale these coordinate like
<vertex x="15*factor" y="15.2*factor"/>
with factor=0.2
(a number)
I was thinking about using re
. Something like:
re.sub(r'(x=\"[0-9]\"', X, X*factor, data)
I prefer not two loop over all lines, and split
and so one...
since I'm reading the file as one string
f = open(filename)
data = f.read()
f.close()
EDIT:
More context
<polygon>
<vertex x="-15" y="15"/>
<vertex x="-15" y="-15"/>
</polygon>
<polygon>
<vertex x="15" y="-15"/>
<vertex x="15" y="15"/>
</polygon>
<polygon>
<vertex x="-15" y="-15"/>
<vertex x="15" y="-15"/>
</polygon>
Output for factor=0.1
<polygon>
<vertex x="-1.5" y="1.5"/>
<vertex x="-1.5" y="-1.5"/>
</polygon>
<polygon>
<vertex x="1.5" y="-1.5"/>
<vertex x="1.5" y="1.5"/>
</polygon>
<polygon>
<vertex x="-1.5" y="-1.5"/>
<vertex x="1.5" y="-1.5"/>
</polygon>
Any ideas?