title: Python 2.7, TypeError: 'module' object is not callable (referring to command-line argument)
body: <p>I've used command-line arguments with argparse many times, but I can't seem to figure out why I am getting a TypeError when trying to use these arguments.  I have written a script that will take 5 required arguments.  I've included the script below.  The argument values are just several directories or file paths.  Any idea what I am doing wrong here?  </p>
  
  <p>Here is the traceback:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/program.py", line 186, in &lt;module&gt;
      sys.exit(builder.main())
    File "C:/program.py", line 119, in main
      filename_config = os.path(self.config)
  TypeError: 'module' object is not callable
  </code></pre>
  
  <p>Here is the code:</p>
  
  <pre><code>import argparse
  import sys
  import os
  import re
  from tempfile import mkstemp
  from shutil import move
  from os import remove, close
  
  
  class Builder():
      def __init__(self):
          parser = argparse.ArgumentParser(description='builder: ' + 'version 1.0.0')
          parser.add_argument('-s', '--source', help="source dir", type=str)
          parser.add_argument('-t', '--target', help="destination dir.", type=str)
          parser.add_argument('-l', '--lua', help="path and filename of lua code", type=str)
          parser.add_argument('-c', '--config', help="path and filename of configuration", type=str)
          parser.add_argument('-d', '--documentation', help="path and filename of documentation", type=str)
          args = parser.parse_args()
  
          self.source = args.source
          self.target = args.target
          self.lua = args.lua
          self.config = args.config
          self.documentation = args.documentation
  
          if not os.path.isdir((self.target)):
              os.makedirs(self.target)
  
      def replace_lua(self, filename, pattern, subst):
          #Create temp file
          fh, abs_path = mkstemp()
          new_file = open(abs_path,'w')
          old_file = open(os.path.join(self.source, filename))
          for line in old_file:
              new_file.write(line.replace(pattern, subst))
          #close temp file
          new_file.close()
          close(fh)
          old_file.close()
          #Move new file
          move(abs_path, os.path.join(self.target, filename))
  
      def replace_version(self, filename, pattern, subst):
          old_file_path = os.path.join(self.target, filename)
          #Create temp file
          fh, abs_path = mkstemp()
          new_file = open(abs_path,'w')
          old_file = open(old_file_path)
          for line in old_file:
              new_file.write(line.replace(pattern, subst))
          #close temp file
          new_file.close()
          close(fh)
          old_file.close()
          #Remove original file
          remove(old_file_path)
          #Move new file
          move(abs_path, os.path.join(self.target, filename))
  
      def replace_documentation(self, filename, pattern, subst):
          old_file_path = os.path.join(self.target, filename)
          #Create temp file
          fh, abs_path = mkstemp()
          new_file = open(abs_path,'w')
          old_file = open(old_file_path)
          for line in old_file:
              new_file.write(line.replace(pattern, subst))
          #close temp file
          new_file.close()
          close(fh)
          old_file.close()
          #Remove original file
          remove(old_file_path)
          #Move new file
          move(abs_path, os.path.join(self.target, filename))
  
  
      def main_XXX(self):
          if not os.path.isdir(self.target):
              os.makedirs(self.target)
  
          #lua pattern
          pattern = "&lt;script&gt;&lt;![CDATA[]]&gt;&lt;/script&gt;"
          filename_lua = os.path(self.lua)
          with open(filename_lua, 'r') as f:
              read_lua = f.read()
              f.closed
          subst = "&lt;script&gt;&lt;![CDATA[\n" + read_lua + "\n]]&gt;&lt;/script&gt;"
  
          #version pattern
          old_version = "&lt;version&gt;1&lt;/version&gt;"
          new_version = "&lt;version&gt;2&lt;/version&gt;"
  
          #documentation
          old_doc = "&lt;documentation&gt;&lt;/documentation&gt;"
          filename_doc = os.path(self.documentation)
          with open(filename_doc, 'r') as f:
              read_doc = f.read()
              f.closed
          read_doc = "&lt;documentation&gt;\n" + read_doc + "\n&lt;/documentation&gt;"
  
          for subdir, dirs, files in os.walk(self.source):
              for file in files:
                  print os.path.join(subdir, file)
                  #file_path = os.path.join(subdir, file)
                  self.replace_lua(file, pattern, subst)
                  #replace_version(file, old_version, new_version)
                  self.replace_documentation(file, old_doc, read_doc)
  
  
      def main(self):
          #create expression objects
          version = re.compile(r"^(\s*)&lt;version&gt;.*&lt;/version&gt;\s*")
          mod_date = re.compile(r"^(\s*)&lt;modified&gt;.*&lt;/modified&gt;\s*")
          lua_script = re.compile(r"^(\s*)&lt;script&gt;.*&lt;/script&gt;\s*")
          doc = re.compile(r"^(\s*)&lt;documentation&gt;.*&lt;/documentation&gt;\s*")
  
          #get version 
          filename_config = os.path(self.config)
          with open(filename_config, 'r') as f:
              for line in f:
                  m_obj = version.search(line)
                  if m_obj:
                      new_version = line
                  else:
                      m_obj = mod_date.search(line)
                      if m_obj:
                          new_mod_date = line + "\n"
              f.closed
  
  
          filename_doc = os.path(self.documentation)
          with open(filename_doc, 'r') as f:
              new_doc = f.read()
              f.closed
          new_doc = "&lt;documentation&gt;\n" + new_doc + "\n&lt;/documentation&gt;\n"
  
  
          filename_lua = os.path(self.lua)
          with open(filename_lua, 'r') as f:
              new_lua = f.read()
              f.closed
  
  
          #iterate
          for subdir, dirs, files in os.walk(self.source):
              for file in files:
                  print os.path.join(subdir, file)
  
                  #Create temp file
                  fh, abs_path = mkstemp()
                  new_file = open(abs_path,'w')
                  old_file = open(os.path.join(self.source, file))
  
                  for line in old_file:
                      m_obj = version.search(line)
                      if m_obj:
                          new_file.write(m_obj.group(1) + new_version)
                      else:
                          m_obj = mod_date.search(line)
                          if m_obj:
                               new_file.write(m_obj.group(1) + new_mod_date)
                          else:
                              m_obj = doc.search(line)
                              if m_obj:
                                   new_file.write(m_obj.group(1) + new_doc)
                              else:
                                  m_obj = lua_script.search(line)
                                  if m_obj:
                                      new_file.write(m_obj.group(1) + "&lt;script&gt;&lt;![CDATA[\n" + new_lua + "\n]]&gt;&lt;/script&gt;\n")
                                  else:
                                      new_file.write(line)
  
                  #close temp file
                  new_file.close()
                  close(fh)
                  old_file.close()
                  #Move new file
                  move(abs_path, os.path.join(self.target, file))
  
  
  if __name__ == "__main__":
      builder = Builder()
      sys.exit(builder.main())
  </code></pre>