TypeError:参数1在运行程序时必须具有“write”方法

时间:2017-04-24 23:35:01

标签: python python-3.x typeerror

我遇到了typeError问题:

def compare(datafile,logfile,index_data,index_log,index_temp):
    datafile_csv = csv.reader(datafile, delimiter = ',',quotechar = '"')
    logfile_csv = csv.reader(logfile,delimiter = ',', quotechar = '"')
    row_data = []
    row_log = []
    row_data = datafile_csv.__next__()
    row_log = logfile_csv.__next__()
    logfile_len = sum (1 for lines in logfile_csv)
------>>>>#this is the part of code that is giving me an issue
    **out_write = csv.writer('resultfile',quoting=csv.QUOTE_ALL)**
    #need to think about it
    while index_data != logfile_len:
            if row_data[index_data:] == row_log [index_log:]:
                    out_writer.writerow(row_log)
                    index_data += 1
                    index_log += 1
                    index_temp = index_log
            else :
                    while row_data [index_data:] != row_log [index_temp:]:
                            index_temp += 1
                            if row_data[index_data:] == row_log [index_log:]:
                                    out_writer.writerow(row_log)
                    index_temp = index_log
    gui.msgbox('This is the name of the newly generated log file :', out_writer)

我正在阅读许多示例,似乎语法正确。

我犯的错误是什么?

感谢和问候

Danilo的

1 个答案:

答案 0 :(得分:0)

with open('resultfile','w') as csvfile:
    out_write = csv.writer(csvfile, quoting=csv.QUOTE_ALL)