title: Trying to write to file within nested loop, but only getting one record
body: <p>Thank you ahead of time for any help you can be in solving this mystery here. I'm a newbie to Python, so you may have much more sophisticated ways of making this work. Please bear with my code. </p>
  
  <p>I'm trying to figure out why when I print the each_file and awl_counter variables I get the list of items that I want, but when I go to write them to the file, I only have one record. I want to make this all work within the loops because there's a lot of recursive activity happening.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>    ## Mini-project 3 (Task A): Calculate percentage of words in ICNALE_Smoke corpus 
  ##                         texts that occurs in the AWL
  ## Assignment:
  ##   1. Read in a list of AWL words
  ##   2. Iterate through all learner files
  ##   3. Clean each learner file
  ##  4. Calculate number of AWL words / total number of words
  ##  5. Output your results
  
  
  # Import Packages
  from __future__ import division     # Allows for division functions
  import string                       # Allows string functions
  import glob                         # Makes a list of all files in a folder
  # import nltk                         # Imports natural language toolkit (NLTK)
  from collections import Counter     # Allows us to create dictionaries for frequency counts
  import fileinput                    # Allows us to concatenate contents of separate text files
  
  
  ##
  ## 1. Read in a list of AWL words
  ##
  awl_word_list = file ("AWL.txt", "rU").read().split("\n")   # Copy contents of AWL to variable and split
  
  
  ##
  ## 2. Iterate through all learner files
  ##
  smoke_file_list = glob.glob("ICNALE_500_smoke/*.txt")  # Collect list of ICNALE texts 
  
  
  # Central loop to perform steps 2-5
  for each_file in smoke_file_list:
  
      current_file_container = []     # Opens empty list for file contents
  
      # Append contents of current file to current_file_container variable
      with open(each_file) as current_file:
          current_file_container.append(current_file.read())
  
      # Convert current_file_container (list) to string       
      clean_string = str(current_file_container)
  
      # Convert clean_string to lowercase
      clean_string_lower = clean_string.lower()
  
      # Remove punctuation marks from clean_string_lower
      punctuation_marks = [",",".","?","'",'"',"!",":",";","(",")","''","``","--"]
      for these_particular in punctuation_marks:
          clean_string_lower = clean_string_lower.replace(these_particular, "")
  
      # Remove additional characters from clean_string_lower
      clean_string_final = filter(lambda x: x in string.printable, clean_string_lower)
  
      # Split clean_string_final and establish total word count
      clean_string_final_split = clean_string_final.split(" ")
      total_word_count = len(clean_string_final_split)
  
      # Establish and reset counter for each Smoke text file
      awl_counter = 0
  
      for current_word in clean_string_final_split:
          if current_word in awl_word_list:
              awl_counter += 1
          else:
              continue
  
  
  #   Open text file and output tab-delimited filename with percentage of AWL hits 
  #   with open("Percent of Words in AWL.txt", "w") as write_to_file:
  #       write_to_file.write(each_file + "\t" + str(awl_counter / total_word_count)) 
  </code></pre>