0
如何在csv文件中同时读写。在制表符分隔的csv文件中追加新列的最佳方法
def read_txt_file(txt_filename):
def get_all_sheet_values(filename):
lines = []
myFile= open(filename, "rU")
for aRow in myFile:
val = aRow.split('\t')
val = map(lambda s: s.strip(), val)
if len(val) > 1 :
print val
lines.append(val)
myFile.close()
return lines
files_dict = get_all_sheet_values(txt_filename)
return files_dict
所以基本上这段代码工作文件。
我的问题是写入相同的csv文件。 例如,
10 10 10 10 10 \n
11 11 11 11 11 \n
22 22 22 22 22 \n
所以每次迭代一行之后我不得不状态添加到它。
10 10 10 10 10 correct time1 \n
11 11 11 11 11 wrong time2 \n
22 22 22 22 22 correct time3 \n
谢谢。