1

Topic: [Python] the Problem with xml.etree.cElementTree

2

Re: [Python] the Problem with xml.etree.cElementTree

Hello, SmaLL75, you wrote: SLL> SLL> for event, elem in ET.iterparse (xml, events = ('start ', ' end ')): SLL> if event is "start": SLL>.... SLL> At least "is" it is impossible to use for string comparison.

3

Re: [Python] the Problem with xml.etree.cElementTree

Hello, Senyai, you wrote: S> Hello, SmaLL75, you wrote: SLL>> SLL>> for event, elem in ET.iterparse (xml, events = ('start ', ' end ')): SLL>> if event is "start": SLL>>.... SLL>> S> At least "is" it is impossible to use for string comparison. It is possible or is impossible, but the condition works also it how cannot cause the pass of the data, i.e. in elem there should be always 33 elements, and actually this amount changes chaotically

4

Re: [Python] the Problem with xml.etree.cElementTree

Hello, SmaLL75, you wrote: SLL> it is possible or it is impossible, but the condition works also it how cannot cause the pass of the data, i.e. in elem there should be always 33 elements, and actually this amount changes chaotically Forgive, you state, what the condition "is" works? It just chaotically works. Replace on "==".

5

Re: [Python] the Problem with xml.etree.cElementTree

Hello, Senyai, you wrote: S> Hello, SmaLL75, you wrote: SLL>> it is possible or it is impossible, but the condition works also it how cannot cause the pass of the data, i.e. in elem there should be always 33 elements, and actually this amount changes chaotically S> Forgive, you state, what the condition "is" works? It just chaotically works. Replace on "==". Thanks for involvement, but changed nothing. for event, elem in ET.iterparse (xml, events = ('start ', ' end ')): record = {} if event == "start": if elem.tag == "{http://schemas.openxmlformats.org/spreadsheetml/2006/main} r": for rnum, item in enumerate (elem): if len (elem)! = 33 and rnum == 0: print (item.attrib [' v ']) record.update ({rnum: item.attrib [' v ']}) rec = list (record.values ()) record.clear () f.write (";".join (rec) + "\n") elem.clear ()

6

Re: [Python] the Problem with xml.etree.cElementTree

Hello, SmaLL75, you wrote: SLL> Hello, Senyai, you wrote: S>> Hello, SmaLL75, you wrote: SLL>>> it is possible or it is impossible, but the condition works also it how cannot cause the pass of the data, i.e. in elem there should be always 33 elements, and actually this amount changes chaotically S>> Forgive, you state, what the condition "is" works? It just chaotically works. Replace on "==". SLL> Thanks for involvement, but changed nothing. SLL> SLL> for event, elem in ET.iterparse (xml, events = ('start ', ' end ')): SLL> record = {} SLL> if event == "start": SLL> if elem.tag == "{http://schemas.openxmlformats.org/spreadsheetml/2006/main} r": SLL> for rnum, item in enumerate (elem): SLL> if len (elem)! = 33 and rnum == 0: SLL> print (item.attrib [' v ']) SLL> record.update ({rnum: item.attrib [' v ']}) SLL> rec = list (record.values ()) SLL> record.clear () SLL> f.write (";" .join (rec) + "\n") SLL> elem.clear () SLL> On resulted in the first post xml, in f registers: 3632025024;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;1;0;0;0;177230;0;0;0;0;0;0;0;0;2014-10-17T00:00:00;1051;0;0 \n ' 3632369876;0;0;0;0;0;1;1;1;0;0;0;0;0;0;0;1;0;1;0;214239;0;1;0;1;1;0;0;0;2016-07-22T00:00:00;407;1;0 \n ' that looks correctly. How to repeat the pass of the data? ( 1 hour)

7

Re: [Python] the Problem with xml.etree.cElementTree

Hello, Senyai, you wrote: S> Hello, SmaLL75, you wrote: SLL>> Hello, Senyai, you wrote: S>>> Hello, SmaLL75, you wrote: SLL>>>> it is possible or it is impossible, but the condition works also it how cannot cause the pass of the data, i.e. in elem there should be always 33 elements, and actually this amount changes chaotically S>>> Forgive, you state, what the condition "is" works? It just chaotically works. Replace on "==". SLL>> Thanks for involvement, but changed nothing. SLL>> SLL>> for event, elem in ET.iterparse (xml, events = ('start ', ' end ')): SLL>> record = {} SLL>> if event == "start": SLL>> if elem.tag == "{http://schemas.openxmlformats.org/spreadsheetml/2006/main} r": SLL>> for rnum, item in enumerate (elem): SLL>> if len (elem)! = 33 and rnum == 0: SLL>> print (item.attrib [' v ']) SLL>> record.update ({rnum: item.attrib [' v ']}) SLL>> rec = list (record.values ()) SLL>> record.clear () SLL>> f.write (";".join (rec) + "\n") SLL>> elem.clear () SLL>> S> On resulted in the first post xml, in f registers: S> S>3632025024;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;1;0;0;0;177230;0;0;0;0;0;0;0;0;2014-10-17T00:00:00;1051;0;0 \n ' S>3632369876;0;0;0;0;0;1;1;1;0;0;0;0;0;0;0;1;0;1;0;214239;0;1;0;1;1;0;0;0;2016-07-22T00:00:00;407;1;0 \n ' S> S> that looks correctly. How to repeat the pass of the data? ( 1 hour) iterparse reads a file units on 16. If a file of less than one unit the parcer works normally, but for me a file 100. It is possible to multiply the unit with a tag "r" for creation of a file of necessary volume.

8

Re: [Python] the Problem with xml.etree.cElementTree

S>> On resulted in the first post xml, in f registers: S>> S>>3632025024;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;1;0;0;0;177230;0;0;0;0;0;0;0;0;2014-10-17T00:00:00;1051;0;0 \n ' S>>3632369876;0;0;0;0;0;1;1;1;0;0;0;0;0;0;0;1;0;1;0;214239;0;1;0;1;1;0;0;0;2016-07-22T00:00:00;407;1;0 \n ' S>> S>> that looks correctly. How to repeat the pass of the data? ( 1 hour) SLL> iterparse reads a file units on 16. If a file of less than one unit the parcer works normally, but for me a file 100. SLL> It is possible to multiply the unit with a tag "r" for creation of a file of necessary volume. Remarkably - could repeat. The documentation says that on event "start" all elements will not be accessible: Note iterparse () only guarantees that it has seen the ">" character of a starting tag when it emits a "start" event, so the attributes are defined, but the contents of the text and tail attributes are undefined at that point. The same applies to the element children; they may or may not be present. If you need a fully populated element, look for "end" events instead. I tried to replace on "end" and all looks as it is necessary. The main thing elem.clear () not to cause when it is not necessary, differently attrib will be empty.

9

Re: [Python] the Problem with xml.etree.cElementTree

Hello, Senyai, you wrote: S>>> On resulted in the first post xml, in f registers: S>>> S>>>3632025024;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;1;0;0;0;177230;0;0;0;0;0;0;0;0;2014-10-17T00:00:00;1051;0;0 \n ' S>>>3632369876;0;0;0;0;0;1;1;1;0;0;0;0;0;0;0;1;0;1;0;214239;0;1;0;1;1;0;0;0;2016-07-22T00:00:00;407;1;0 \n ' S>>> S>>> that looks correctly. How to repeat the pass of the data? ( 1 hour) SLL>> iterparse reads a file units on 16. If a file of less than one unit the parcer works normally, but for me a file 100. SLL>> It is possible to multiply the unit with a tag "r" for creation of a file of necessary volume. S> it is remarkable - could repeat. S> the documentation says that on event "start" all elements will not be accessible: S> S> Note S> iterparse () only guarantees that it has seen the ">" character of a starting tag when it emits a "start" event, so the attributes are defined, but the contents of the text and tail attributes are undefined at that point. The same applies to the element children; they may or may not be present. S> If you need a fully populated element, look for "end" events instead. S> I tried to replace on "end" and all looks as it is necessary. The main thing elem.clear () not to cause when it is not necessary, differently attrib will be empty. Thanks, the kind person! All earned.