请帮助解决TypeError问题。它适用于pyhton 2,但不适用于python 3。
Python2:
def ExchangeColumns(RECXX_Output,Modified_Recxx_Output,column1,column2,column3,column4,column5,column6):
with open(RECXX_Output) as infile ,open(Modified_Recxx_Output, 'wb') as outfile:
reader = csv.DictReader(infile)
append = (column1,column2,column3,column4,column5,column6)
outfile.write(','.join(append)+'\n')
Python3:
def ExchangeColumns(RECXX_Output,Modified_Recxx_Output,column1,column2,column3,column4,column5,column6):
with open(RECXX_Output) as infile ,open(Modified_Recxx_Output, 'wb') as outfile:
reader = csv.DictReader(infile)
append = (column1,column2,column3,column4,column5,column6)
appendb = str.encode(append)
outfile.write(b','.join(appendb)+b'\n')
##outfile.write(b','.join(append).encode(encoding='utf-8')+b'\n')
答案 0 :(得分:0)
问题的答案是-您有一个元组对象,而不是字符串。
答案 1 :(得分:0)
在将文件打开为'w'而不是'wb'后起作用了
with open(RECXX_Output) as infile ,open(Modified_Recxx_Output, 'w') as outfile: