TypeError: coercing to Unicode: need string or buffer, list found

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.

Leave a Comment