title: IndexError: list index out of range - PythonError
body: <p>I'm creating a program that should create a file (.txt) based on each line of 'clouds.txt'. This is my code:</p>
  <pre><code>def CreateFile():
      global file_name
      f = open(file_name,&quot;w+&quot;)
      f.write(list_email + &quot;:&quot;)
      f.close()
  
  def WriteInConfig():
      f = open(&quot;config/config.txt&quot;,&quot;a&quot;)
      f.write(list_name + &quot;\n&quot;)
      f.close()
  
  
  
  with open(&quot;clouds.txt&quot;,&quot;r&quot;) as f:
      
      list_lines = sum(1 for line in open('clouds.txt'))
      
      lines = f.readline()
      for line in lines:
              
          first_line = f.readline().strip()
          list_email = first_line.split('|')[1] #email
          print(&quot;Email: &quot; + list_email)
  
          list_pass = first_line.split('|')[2] #pass
          print(&quot;Pass: &quot; + list_pass)
              
          list_name = first_line.split('|')[3] #name
          print(list_name)
  
          global file_name
          file_name = &quot;config/.&quot; + list_name + &quot;.txt&quot;
  
          with open('clouds.txt', 'r') as fin:
              data = fin.read().splitlines(True)
          with open('clouds.txt', 'w') as fout:
              fout.writelines(data[1:])
  
          CreateFile()
          WriteInConfig()
  </code></pre>
  <p>The clouds.txt file looks like this:</p>
  <pre><code>&gt;|clouds.n1c0+mega01@gmail.com|cwSHklDIybllCD1OD4M|Mega01|15|39.91|FdUkLiW0ThDeDkSlqRThMQ| |x
  |clouds.n1c0+mega02@gmail.com|tNFVlux4ALC|Mega02|50|49.05|lq1cTyp13Bh9-hc6cZp1RQ|xxx|x
  |clouds.n1c0+mega03@gmail.com|7fe4196A4CUT3V|Mega03|50|49.94|BzW7NOGmfhQ01cy9dAdlmg|xxx|xxx &gt;
  </code></pre>
  <p>Everything works fine until 'Mega48'. There I get &quot;IndexError: list index out of range&quot;</p>
  <pre><code>&gt;|clouds.n1c0+mega47@gmail.com|bd61t9zxcuC1Yx|Mega47|50|10|Xjff6C8mzEqpa3VcaalUuA|xxx|x
  |clouds.n1c0+mega48@gmail.com|kBdnyB6i0PUyUb|Mega48|50|0|R6YfuGP2hvE-uds0ylbQtQ|xxx|x
  |clouds.n1c0+mega49@gmail.com|OcAdgpS4tmSLTO|Mega49|50|28.65|xxx|  &gt;
  </code></pre>
  <p>I checked and there are no spaces/other characters. As you could see, after creating the file, the program deletes the line. After the error, if I'm starting the program again (and starts from 'Mega47') it doesn't show the error, and everything works as planned.</p>
  <p>Any ideas how to fix this?</p>