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

╄→гoц情女王★ 提交于 2019-11-27 23:55: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.

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="+".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!