title: Python - reading a single file, extracting data from it, and then writing it to many files
body: <p>I am trying to read 1 file, parse data from it then write each parsed column to another file in a different directory. Here is my code:</p>
  
  <pre><code>os.makedirs("new_directory")
  my_file = open("original_file.txt", "r+")
  output = "new_file.txt"
  outputfile = open("new_directory/"+output, "w")
  num = 3
  
  for line in my_file:
      line = line.split("\t")
      sample = line[num]
      lst = line[1] + "\t" + line[2] + "\t" + sample + "\n"
      outputfile.write(lst)
  </code></pre>
  
  <p>This is as far as I have got. I want to write multipe output files with different information from the original file, and save them all in the new directory. How can I write a loop to change the output file name each time - I was trying to increment 'num' and then maybe add it to the output variable:</p>
  
  <pre><code>output = "new_file" + num + ".txt"
  outputfile = open("new_directory/"+output, "w")
  </code></pre>
  
  <p>Or something like this. Is there a better way? </p>