Often one needs to give as argument an existing file, so we have a check for
that, that can be used with argparse. However, sometimes you want to give
users the option to not give a filename at all, which is what this new
checker allows.
if isfile(filename):
return filename
raise ArgumentTypeError('{} is not an existing file'.format(filename))
+
+
+def existing_file_or_empty(filename=''):
+ """
+ Like :py:func:`existing_file` but accepts empty filename (returns '' then).
+ """
+ if not filename.strip():
+ return ''
+ return existing_file(filename)