title: Reads Path>File as String - "AttributeError: 'str' object has no attribute 'open'" Why?
body: <p>In the code below it reads the out_file as a string and I can't seem to figure out why. If I do not treat it as a string then it says the file location is incorrect. It reads the src_dir fine apparently. Thanks in advance for any help. I'm very new to python and teaching myself.</p>
  
  <pre><code>import os
  import os.path
  import shutil
  
  '''This is supposed to read through all the text files in a folder and
  copy the text inside to a master file.'''
  
  #   This gets the source and target directories for reading writing the
  #   files respectively
  
  src_dir = r'E:\filepath\text_files'
  out_file = r'E:\filepath\master.txt'
  files = (os.listdir(src_dir))
  def valid_path(dir_path, filename):
      full_path = os.path.join(dir_path, filename)
      return os.path.isfile(full_path)
  file_list = [os.path.join(src_dir, f) for f in files if valid_path(src_dir, f)]    
  
  
  #   This should open the directory and make a string of all the files
  #   listed in the directory. I need it to open them one by one, write to the
  #   master file and close it when completely finished.
  
  
  open(out_file, 'a+')
  with out_file.open() as outfile:
      for element in file_list:
          open(element)
          outfile.append(element.readlines())
  
  out_file.close()
  
  print 'Finished'
  </code></pre>