I am new to Python and barely know about lists and tuples. I have a program to execute which takes several values as input argument. Below is the list of input args
parser = argparse.ArgumentParser()
parser.add_argument("server")
parser.add_argument("outdir")
parser.add_argument("dir_remove", help="Directory prefix to remove")
parser.add_argument("dir_prefix", help="Directory prefix to prefix")
parser.add_argument("infile", default=[], action="append")
options = parser.parse_args()
The program works fine with the following command
python prod2dev.py mysrv results D:\Automations D:\MyProduction Automation_PP_CVM.xml
But looking at the code, it seems like the code can accept multiple file names for argument "infile". I have tried following to pass multiple file names but none worked.
python prod2dev.py mysrv results D:\Automations D:\MyProduction "Automation_PP_CVM.xml, Automation_PT_CVM.xml"
python prod2dev.py mysrv results D:\Automations D:\MyProduction ["Automation_PP_CVM.xml", "Automation_PT_CVM.xml"]
python prod2dev.py mysrv results D:\Automations D:\MyProduction ['Automation_PP_CVM.xml', 'Automation_PT_CVM.xml']
python prod2dev.py mysrv results D:\Automations D:\MyProduction ['"Automation_PP_CVM.xml"', '"Automation_PT_CVM.xml"']
The code below is apparently traversing the list
infile = windowsSucksExpandWildcards(options.infile)
for filename in infile:
print(filename)
outfilename = os.path.join(options.outdir, os.path.split(filename)[1])
if os.path.exists(outfilename):
raise ValueError("output file exists: {}".format(outfilename))
with open(filename, "rb") as f:
root = lxml.etree.parse(f)
if not isEnabled(root):
print("Disabled. Skipping.")
continue
elif not hasEnabledTriggers(root):
print("Has no triggers")
continue
...
...
...
def windowsSucksExpandWildcards(infile):
result = []
for f in infile:
tmp = glob.glob(f)
if bool(tmp):
result.extend(tmp)
else:
result.append(f)
return result
Please guide on how to pass multiple filenames (strings) to a single argument "infile" which is apparently a list.
I'm running Python 3.5.1 |Anaconda 4.0.0 (32-bit)