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