How to pass files to script with glob AND specific path, with error if path does not exist?
<p>I have a script that usually needs to perform one of two tasks: 1) process a bunch of files with paths expanded from a wildcard expansion. 2) process specific files with definite paths. I've been using glob to handle the wildcard expansion, but this raises a problem. Because glob only returns paths that actually exist, the code won't generate an error if a specific path to a nonexistent file is given by the user. Below is a minimal working example (MWE) of the code. The MWE happily processes existing files expanded from the wildcard, but does not generate the desired error message because glob only returns existing paths. How can I modify this to behave as desired?</p>

<pre><code>#!/usr/bin/env python3

import argparse, glob, sys, os

parser = argparse.ArgumentParser()
parser.add_argument("src_path", metavar="path", type=str,
    help="Path to files to be merged; enclose in quotes, accepts * as wildcard for directories or filenames")

args = parser.parse_args()
files = glob.iglob(args.src_path)

for file in files:
    try:    
        with open(file, 'r') as f:
            sys.stdout.write('File exists: ' + file + '\n') 
    except IOError:
        sys.stderr.write('File does not exist: ' + file + '\n') 
</code></pre>
