existant_file¶
-
yoda_powers.toolbox.
existant_file
(path)[source]¶ ‘Type’ for argparse - checks that file exists and return the absolute path as PosixPath() with pathlib
Notes
function need modules:
pathlib
argparse
- Parameters
path (str) – a path to existent file
- Returns
Path(path).resolve()
- Return type
PosixPath
- Raises
ArgumentTypeError – If file path does not exist.
ArgumentTypeError – If path is not a valid file.
Examples
>>> import argparse >>> parser = argparse.ArgumentParser(prog='test.py', description='''This is demo''') >>> parser.add_argument('-f', '--file', metavar="<path/to/file>",type=existant_file, required=True, dest='path_file', help='path to file')