Python 在以制表符分隔的csv文件中追加新列的最佳方法
如何在csv文件中同时读写Python 在以制表符分隔的csv文件中追加新列的最佳方法,python,Python,如何在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(v
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 correct time1 \n
11 11 11 11 11 wrong time2 \n
22 22 22 22 22 correct time3 \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