
Jan. 27, 2015
9:49 a.m.
Charlie Clark schrieb am 27.01.2015 um 17:51:
Am .01.2015, 17:38 Uhr, schrieb jens quade:
you still copy the attribute values, but all at once:
y.attrib.update(x.items()) x.attrib.clear()
Nice trick!
y.attrib.update(x.attrib) is also possible. I don't know if there's any performance improvement on not calling the items method.
Not currently - the implementation simply calls .items() internally and iterates over it. https://github.com/lxml/lxml/blob/44ec7b535d1a342b3c4b6070ebd2a4c3e29595f7/s... But I personally find it a bit clearer to say "x.attrib.update(y.attrib)", and if it ever gets further optimised (it's fast enough, so don't hold your breath), it would quite likely happen for this idiom. Stefan