title: Reading from two files
body: <p>I am trying to write a script that will take several 2 column files, write the first and second columns from the first one to a result file and then only the second columns from all other files and append them on.</p>
  
  <p>Example:</p>
  
  <pre class="lang-none prettyprint-override"><code>File one                         File two
  Column 1     Column 2            dont take this column      Column 2
  Line 1       Line 2              dont take this column      Line 2
  </code></pre>
  
  <p>The final result should be </p>
  
  <pre><code>Result file
  Column 1    Column 2    Column 2     
  Line1       Line 2      Line 2
  etc
  </code></pre>
  
  <p>I have the almost everything working except for adding the second columns onto the first.  I am taking the ResultFile as r+ and I want to read out the line that's there (the first file data) and then read the corresponding line from the other files, append it, and put it back in.</p>
  
  <p>Here's the code I have for the second section:</p>
  
  <pre class="lang-py prettyprint-override"><code>#Open each subsequent file for 2nd column data
  while n &lt; i:
      with open(FileNames[n], "r") as InputFile
          with ResultFile:
              Temp2 = ResultFile.readline()
              for line in InputFile:
                  Temp2 += line.split(",", 1)[-1]
                  if line == LastValue:
                      break
              if len(ResultFile,readline()) == "":
                  break
          YData += (Temp2 + "\n")
      n += 1
  InputFile.close
  </code></pre>
  
  <p>The break IFs are not working quite right atm I just needed a way to end the infinite loop.  Also LastValue is equal to the last x column value from the first file.</p>
  
  <p>Any help would be appreciated</p>
  
  <p><strong>EDIT</strong><br>
  I'm trying to do this without itertools.</p>