title: Python: Write all files in a directory to one cdv file
body: <p>I am trying to create a bimodal graph of a collection of texts such that I can project a network of either texts by words or words by texts. A colleague of mine has indicated that if I can get all my files in a single csv file of the format below, then has a workflow that will take care of the rest:</p>
  
  <pre><code>textfile1, words words words
  textfile2, words words words
  </code></pre>
  
  <p>I have written the following script:</p>
  
  <pre><code>#! /usr/bin/env python
  
  # a script to convert all text files in a directory to the format:
  # filename, words from file (no punctuation)
  
  import glob
  import re
  
  files = {}
  for fpath in glob.glob("*.txt"):
      with open(fpath) as f:
           just_words = re.sub("[^a-zA-Z'-]"," ",f.read())
  
  with open("mastertext.csv", "w") as f:
      for fname in files:
          print &gt;&gt; f , "%s,%s"%(fname,just_words)
  </code></pre>
  
  <p>This script will run and produce the output file, but the output file is blank and I get no error response -- the source of much learning for me as a Python newbie. Am I on the right track here, and if so what am I missing?</p>