title: Why can't it read the xml data properly?
body: <p>Okay first of all, in my experience as a beginner in programming I never had encounter this kind of weirdness in my whole life.</p>
  <p>Hello I have a very large xml file and I cannot show it here but I can show the first part here as an image</p>
  <p><a href="https://i.stack.imgur.com/TRikh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TRikh.png" alt="First data in XML" /></a></p>
  <p>As you can see the arrows are pointing is the very first  tag along with its respective children. Now I have here a program that reads that <strong>LARGE</strong> xml file and as you can see there is only the first 5 of it, here is the code</p>
  <pre><code>def parse(word,translator,file):
      language_target = &quot;de&quot;
      if os.path.isfile(file):
          data = [] #[(a,b,c),(a,b,c),(a,b,c)]
  
  
          file_path = os.path.join(os.getcwd(),file)
          nsmap = {&quot;xml&quot;: &quot;http://www.w3.org/XML/1998/namespace&quot;}
          for event, elem in ET.iterparse(file_path,events=(&quot;start&quot;,&quot;end&quot;)):
  
              if event == &quot;start&quot; and elem.tag == &quot;tu&quot;:
                  temp_list = []
                  sentence = elem.find(f'.//tuv[@xml:lang=&quot;{language_target}&quot;]', nsmap).find('seg', nsmap).text
  
      else:
          print(&quot;\nNo such File&quot;)
  
  
      os.system(&quot;pause&quot;)
  </code></pre>
  <p>There's no need to give attention much on the parameters, those three just gets a word and a translator and a filename. Now on this part is where I read the <strong>LARGE</strong> xml file</p>
  <pre><code>nsmap = {&quot;xml&quot;: &quot;http://www.w3.org/XML/1998/namespace&quot;}
          for event, elem in ET.iterparse(file_path,events=(&quot;start&quot;,&quot;end&quot;)):
  
              if event == &quot;start&quot; and elem.tag == &quot;tu&quot;:
                  temp_list = []
                  sentence = elem.find(f'.//tuv[@xml:lang=&quot;{language_target}&quot;]', nsmap).find('seg', nsmap).text
  </code></pre>
  <p>What happens there is it gets all of the  tags cause I want to get the text of its children. Now look what happens here when I run the program</p>
  <p><a href="https://i.stack.imgur.com/vQg0X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vQg0X.png" alt="Error without print" /></a></p>
  <p>It says that it is a <code>NoneType</code> object, now I am wondering how can it be a <code>NoneType</code> object where there <code>YOU CAN SEE</code> it is definitely <code>NOT a NoneType Object</code> cause it has the corresponding data and this is the first data and how can it said that it is <strong>NoneType</strong>?</p>
  <pre><code>&lt;tu&gt;
    &lt;tuv xml:lang=&quot;de&quot;&gt;&lt;seg&gt;- Gloucester? ! - Die sollten doch in Serfam sein.&lt;/seg&gt;&lt;/tuv&gt;
    &lt;tuv xml:lang=&quot;en&quot;&gt;&lt;seg&gt;They should have surrendered when they had the chance!&lt;/seg&gt;&lt;/tuv&gt;
  &lt;/tu&gt;
  </code></pre>
  <p>Now look what happens when I put <code>print()</code> right below this code <code>sentence = elem.find(f'.//tuv[@xml:lang=&quot;{language_target}&quot;]', nsmap).find('seg', nsmap).text</code></p>
  <p>So it would be like this:</p>
  <pre><code>sentence = elem.find(f'.//tuv[@xml:lang=&quot;{language_target}&quot;]', nsmap).find('seg', nsmap).text
  print(sentence)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/j4KAV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/j4KAV.png" alt="IT WORKS" /></a></p>
  <p>As you can see now it works! however it stopped again on a specific data but I checked it and it is not <code>NoneType</code> there is <strong>DATA</strong>  on that part and I am wondering why is it saying it to be <code>NoneType</code>. Also I am so mindblown by the fact that I just put a <code>print()</code> function below the <code>sentence</code> code and it made a lot of difference. Can someone help me with this? To be honest I am really mindblown by this and I do not know what is happening, I feel like there is a lack of understanding that I am having in reading the XML file with python. Can someone help me with it and guide me? maybe there's a better way to do this.</p>
  <p>Thank you so much! I really need your help stackoverflow community! Thank you!</p>
  <p>Also here I made a run again and got this result</p>
  <pre><code>Jeremiah! Jetzt bist du dran!
  Jeremiah, this is a purge!
  Traceback (most recent call last):
    File &quot;us24.py&quot;, line 76, in &lt;module&gt;
      parse(word,translator,file)
    File &quot;us24.py&quot;, line 35, in parse
      english_translation = elem.find('.//tuv[@xml:lang=&quot;en&quot;]', nsmap).find('seg', nsmap).text #Human Translation
  AttributeError: 'NoneType' object has no attribute 'find'
  </code></pre>
  <p>and it again said <strong>NoneType</strong> where in fact I looked at my xml file and there is <strong>DATA</strong> on it!</p>
  <pre><code>&lt;tu&gt;
        &lt;tuv xml:lang=&quot;de&quot;&gt;&lt;seg&gt;Jeremiah! Jetzt bist du dran!&lt;/seg&gt;&lt;/tuv&gt;
        &lt;tuv xml:lang=&quot;en&quot;&gt;&lt;seg&gt;Jeremiah, this is a purge!&lt;/seg&gt;&lt;/tuv&gt;
      &lt;/tu&gt;
      &lt;tu&gt;
        &lt;tuv xml:lang=&quot;de&quot;&gt;&lt;seg&gt;Suzaku!&lt;/seg&gt;&lt;/tuv&gt;
        &lt;tuv xml:lang=&quot;en&quot;&gt;&lt;seg&gt;Suzaku-kun!&lt;/seg&gt;&lt;/tuv&gt;
      &lt;/tu&gt;
      &lt;tu&gt;
        &lt;tuv xml:lang=&quot;de&quot;&gt;&lt;seg&gt;- CÃ©cile-san? !&lt;/seg&gt;&lt;/tuv&gt;
        &lt;tuv xml:lang=&quot;en&quot;&gt;&lt;seg&gt;Cecil-san!&lt;/seg&gt;&lt;/tuv&gt;
      &lt;/tu&gt;
      &lt;tu&gt;
        &lt;tuv xml:lang=&quot;de&quot;&gt;&lt;seg&gt;- Hier ist's zu gefahrlich!&lt;/seg&gt;&lt;/tuv&gt;
        &lt;tuv xml:lang=&quot;en&quot;&gt;&lt;seg&gt;It's dangerous here!&lt;/seg&gt;&lt;/tuv&gt;
      &lt;/tu&gt;
  </code></pre>
  <p>The next one it should be reading is this , but it says <strong>NoneType</strong> how can it be Nonetype where you can see it has the correct data and why are the others working besides this one? :(</p>
  <pre><code>&lt;tu&gt;
        &lt;tuv xml:lang=&quot;de&quot;&gt;&lt;seg&gt;Suzaku!&lt;/seg&gt;&lt;/tuv&gt;
        &lt;tuv xml:lang=&quot;en&quot;&gt;&lt;seg&gt;Suzaku-kun!&lt;/seg&gt;&lt;/tuv&gt;
      &lt;/tu&gt;
  </code></pre>