I\'m trying to get a data parsing script up and running. It works as far as the data manipulation is concerned. What I\'m trying to do is set this up so I can enter multiple
args.infile
is a list of filenames, not one filename. Loop over it:
for filename in args.infile:
base, ext = os.path.splitext(filename)
with open("{}1{}".format(base, ext), "wb") as outf, open(filename, 'rb') as inf:
output = csv.writer(outf)
for line in csv.reader(inf):
Here I used os.path.splitext()
to split extension and base filename so you can generate a new output filename adding 1
to the base.
If you specify an nargs
argument to .add_argument
, the argument will always be returned as a list.
Assuming you want to deal with all of the files specified, loop through that list:
for filename in args.infile:
for line in csv.reader(open(filename)):
for item in line[2:]:
#to skip empty cells
[...]
Or if you really just want to be able to specify a single file; just get rid of nargs="+"
.