def str_is_existing_path(path: str) -> str:
"""
>>> import tempfile
>>> with tempfile.TemporaryFile() as f:
... str_is_existing_file(f.name) == f.name
True
>>> with tempfile.TemporaryDirectory() as path:
... str_is_existing_path(path) == path
True
>>> str_is_existing_path('')
Traceback (most recent call last):
argparse.ArgumentTypeError: Given path is not an existing file or directory.
>>> str_is_existing_path('/non/existing/dir')
Traceback (most recent call last):
argparse.ArgumentTypeError: Given path is not an existing file or directory.
"""
if isfile(path) or isdir(path):
return path
else:
raise ArgumentTypeError("Given path is not an existing file or directory.")
评论列表
文章目录