[lxml] Re: Turn three-line block into single?

2022-08-10 Thread Gilles
On 10/08/2022 16:34, Stefan Behnel wrote: Gilles schrieb am 10.08.22 um 15:20: for row in tree.iter("wpt"):      lat,lon = row.attrib.values() Note that this assignment depends on the order of the two attributes in the XML document, i.e. in data that you may not control yourself. It will bre

[lxml] Re: Turn three-line block into single?

2022-08-10 Thread Stefan Behnel
Gilles schrieb am 10.08.22 um 15:20: for row in tree.iter("wpt"):     lat,lon = row.attrib.values() Note that this assignment depends on the order of the two attributes in the XML document, i.e. in data that you may not control yourself. It will break if the provider of your input documents

[lxml] Re: Turn three-line block into single?

2022-08-10 Thread Gilles
On 10/08/2022 13:30, Charlie Clark wrote: Yes, this should work. However, I don't know if adjusting the tree while looping over it won't the same kind of problems as with other sequences in Python. How many elements are there in your tree? Memory use in XML can get very expensive so combining

[lxml] Re: Turn three-line block into single?

2022-08-10 Thread Charlie Clark
On 10 Aug 2022, at 9:53, Gilles wrote: > An important line was missing :-/ > > no_dups = {} > > for row in tree.iter("wpt"): > >     name,lat,lon = [row.find("name").text] + row.attrib.values() > >     if name not in no_dups: > >    no_dups[name] = lat,lon > >     else: > >    #dup = rem

[lxml] Re: Turn three-line block into single?

2022-08-10 Thread Gilles
An important line was missing :-/ no_dups = {} for row in tree.iter("wpt"):     name,lat,lon = [row.find("name").text] + row.attrib.values()     if name not in no_dups:    no_dups[name] = lat,lon     else:    #dup = remove    row.getparent().remove(row) On 09/08/2022 20:59, Gilles