title: Looping a write command to output many different indices from a list separately in Python
body: <p>Im trying to get an output like:</p>
  
  <pre><code>KPLR003222854-2009131105131
  </code></pre>
  
  <p>in a text file. The way I am attempting to derive that output is as such:</p>
  
  <pre><code>with open('Processed_Data.txt', 'r') as file_P, open('KIC_list.txt', 'w') as namelist:
      nameData = []           
      for line in file_P:
          splt_file_P = line.split()
          nameData.append(splt_file_P[0])
      for key in nameData:
          namelist.write('\n' 'KPLR00' + "".join(str(w) for w in nameData) + '-2009131105131')
  </code></pre>
  
  <p>However I am having an issue in that the numbers in the nameData array are all appearing at once in the specified output, instead of using on ID cleanly as shown above the output is something like this:</p>
  
  <pre><code>KPLR00322285472138721382172198371823798123781923781237819237894676472634973256279234987-2009131105131
  </code></pre>
  
  <p>So my question is how do I loop the write command in a way that will allow me to get each separate ID (each has a specific index value, but there are over 150) to be properly outputted.</p>
  
  <p>EDIT:
  Also, some of the ID's in the list are not the same length, so I wanted to add 0's to the front of the 'key' to make them all equal 9 digits. I cheated this by adding the 0's into the KPLR in quotes but not all of the ID's need just two 0's. The question is, could I add 0's between KPLR and the key in any way to match the 9-digit format?</p>