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

前端 未结 2 1038
谎友^
谎友^ 2020-12-06 10:44

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

2条回答
  •  被撕碎了的回忆
    2020-12-06 11:41

    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.

提交回复
热议问题