title: Problem parsing files when extracting filenames os.listdir() as
body: <p>If I use <code>filename = argv[n]</code> from a windows command line, the <code>extract()</code> function below seems to work okay. If I instead use the list of files names from the <code>list(dir)</code>, which uses the <code>os.listdir()</code> built-in function to extract the filenames from the working directory, then the <code>extract()</code> function fails.</p>
  
  <p>The input_file.read() recognises the filename as a valid value, but it seems to fail at <code>date = list(date_match[0]</code>) with 'TypeError: coercing to Unicode: need string or buffer, tuple found'.</p>
  
  <p>It seems that the os.listdir output list values are not normal strings, but something else instead. Any ideas?</p>
  
  <pre><code>import sys
  import re
  import os
  
  def extract(filename):
  
      input_file = open(filename, 'r')
      data = input_file.read() #read file line by line
  
      #make list of time and date
      date_match = re.findall(r'(\d+:\d+)\t(\d+/\d+/\d+)', data) #find file date and time
      date = list(date_match[0])
  
      #extract date tuple from list above
      return date
  
  def list(dir):
      directoryfiles = os.listdir(dir)
      diroutput = []
      for member in directoryfiles:
          if member != sys.argv[0]:
              diroutput.append(member)
      return diroutput
  
  def main():
  
      inputfiles = list(sys.argv[1])
  
      for filename in inputfiles:
          date = extract(filename)
  
  if __name__ == '__main__':
      main()
  </code></pre>