def extant_item(arg, arg_type):
    """Determine if parser argument is an existing file or directory.

    This technique comes from http://stackoverflow.com/a/11541450/95592
    and from http://stackoverflow.com/a/11541495/95592

    Args:
        arg: parser argument containing filename to be checked
        arg_type: string of either "file" or "directory"

    Returns:
        If the file exists, return the filename or directory.

    Raises:
        If the file does not exist, raise a parser error.
    """
    if arg_type == "file":
        if not os.path.isfile(arg):
            raise argparse.ArgumentError(
                None,
                "The file {arg} does not exist.".format(arg=arg))
        else:
            # File exists so return the filename
            return arg
    elif arg_type == "directory":
        if not os.path.isdir(arg):
            raise argparse.ArgumentError(
                None,
                "The directory {arg} does not exist.".format(arg=arg))
        else:
            # Directory exists so return the directory name
            return arg
Determine if parser argument is an existing file or directory.

    This technique comes from http://stackoverflow.com/a/11541450/95592
    and from http://stackoverflow.com/a/11541495/95592

    Args:
        arg: parser argument containing filename to be checked
        arg_type: string of either "file" or "directory"

    Returns:
        If the file exists, return the filename or directory.

    Raises:
        If the file does not exist, raise a parser error.