moving all attributes from one element to another

I want to move all attributes of an element to another element. If the attributes of elements x are x.attrib and attributes = x.attrib, is there a single command that says "take the attribute dictionary of x and attach it to y"? Or do I have to use the .set method for each individual attribute? MM

Am .01.2015, 17:38 Uhr, schrieb jens quade <jq@qdevelop.de>:
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. Charlie -- Charlie Clark Managing Director Clark Consulting & Research German Office Kronenstr. 27a Düsseldorf D- 40217 Tel: +49-211-600-3657 Mobile: +49-178-782-6226

Thanks to both Charlie and Jens. This is a really terrific list: lots of prompt, terse, and good advice, and the noise level is remarkably low. A good example for the world at large Martin Mueller Professor emeritus of English and Classics Northwestern University On 1/27/15 10:51 AM, "Charlie Clark" <charlie.clark@clark-consulting.eu> wrote:

Charlie Clark schrieb am 27.01.2015 um 17:51:
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

Am .01.2015, 17:38 Uhr, schrieb jens quade <jq@qdevelop.de>:
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. Charlie -- Charlie Clark Managing Director Clark Consulting & Research German Office Kronenstr. 27a Düsseldorf D- 40217 Tel: +49-211-600-3657 Mobile: +49-178-782-6226

Thanks to both Charlie and Jens. This is a really terrific list: lots of prompt, terse, and good advice, and the noise level is remarkably low. A good example for the world at large Martin Mueller Professor emeritus of English and Classics Northwestern University On 1/27/15 10:51 AM, "Charlie Clark" <charlie.clark@clark-consulting.eu> wrote:

Charlie Clark schrieb am 27.01.2015 um 17:51:
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
participants (4)
-
Charlie Clark
-
jens quade
-
Martin Mueller
-
Stefan Behnel