code: def existingDirectory(string):
      
      if not os.path.isdir(string):
          argparse.ArgumentTypeError('{} is not a valid directory.'.format(string))
      return string
docs: A custom type for the argparse commandline parser.
      Check whether the supplied string points to a valid directory.
      
      Examples
      --------
      
      >>> parser.add_argument('argname', type=existingDirectory, help='help')