Re: ElementTree and clone element toot

2009-02-08 Thread Stefan Behnel
Aahz wrote: > In article <4986bfd7$0$9385$ba4ac...@news.orange.fr>, > m.banaouas wrote: >> Working with the ElementTree module, I looked for clone element >> function but not found such tool: > > Have you tried using copy.deepcopy()? While being the most obvious solution, calling deepcopy() on a

Re: ElementTree and clone element toot

2009-02-08 Thread Aahz
In article <4986bfd7$0$9385$ba4ac...@news.orange.fr>, m.banaouas wrote: > >Working with the ElementTree module, I looked for clone element >function but not found such tool: Have you tried using copy.deepcopy()? -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ We

Re: ElementTree and clone element toot

2009-02-02 Thread Gabriel Genellina
En Mon, 02 Feb 2009 14:21:29 -0200, m.banaouas escribió: My python version is 2.4.4 def SubElement(parent, tag, attrib={}, **extra): Can you tell me how does "parent" issue could be solved by SubElement ? Simply because you *have* to pass a parent to the function... I'm looking for how t

Re: ElementTree and clone element toot

2009-02-02 Thread m.banaouas
My python version is 2.4.4 def SubElement(parent, tag, attrib={}, **extra): Can you tell me how does "parent" issue could be solved by SubElement ? I'm looking for how to determine element parent just by asking element it self. It seems like element doesn't know witch is its parent, while any par

Re: ElementTree and clone element toot

2009-02-02 Thread Gerard Flanagan
Gabriel Genellina wrote: En Mon, 02 Feb 2009 12:37:36 -0200, Gerard Flanagan escribió: e = ET.fromstring(s) def clone(elem): ret = elem.makeelement(elem.tag, elem.attrib) ret.text = elem.text for child in elem: ret.append(clone(child)) return ret f = clone(e)

Re: ElementTree and clone element toot

2009-02-02 Thread Gabriel Genellina
En Mon, 02 Feb 2009 12:37:36 -0200, Gerard Flanagan escribió: e = ET.fromstring(s) def clone(elem): ret = elem.makeelement(elem.tag, elem.attrib) ret.text = elem.text for child in elem: ret.append(clone(child)) return ret f = clone(e) You forget the tail attri

Re: ElementTree and clone element toot

2009-02-02 Thread Gerard Flanagan
m.banaouas wrote: Hi all, Working with the ElementTree module, I looked for clone element function but not found such tool: def CloneElment(fromElem, destRoot = None) fromElem is the element to clone destRoot is the parent element of the new element ; if None so the new element will be child of

ElementTree and clone element toot

2009-02-02 Thread m.banaouas
Hi all, Working with the ElementTree module, I looked for clone element function but not found such tool: def CloneElment(fromElem, destRoot = None) fromElem is the element to clone destRoot is the parent element of the new element ; if None so the new element will be child of fromElem parent. The