Hello,
As input parameter, I need to allow users to give either a single file (input.txt) or glob (*.txt).
The following code only supports glob:
Thank you.
--
Edit: My mistake. I was using a wrong filename as input. The code above works to handle either a single file or a glob.
As input parameter, I need to allow users to give either a single file (input.txt) or glob (*.txt).
The following code only supports glob:
import sys
import os
from glob import glob
#============= Read file(s) from command line; Windows and *nix shells don't behave the same way
def argGlob(args=None):
if args is None: args = sys.argv
return [subglob for arg in args for subglob in glob(arg)]
arguments = len(sys.argv) - 1
if arguments < 1:
print ("Must pass at least one TXT file, or *.txt")
sys.exit()
for item in argGlob(sys.argv[1:]):What would be the right way to handle both cases?Thank you.
--
Edit: My mistake. I was using a wrong filename as input. The code above works to handle either a single file or a glob.
