我有一个将一堆行写入 csv 文件的代码。它写了我想要的,但是......它在每一列中插入括号......代码是:
root_text_csv = "C:/Users/s/Desktop/text/knife"+numarul_folderelor+".csv"
fisier_text_knife = csv.writer(open(root_text_csv,'wb'))
row_test = []
for filenames in os.listdir(foldere_prrra):
knife = filenames.replace("<SP>", " ").replace(".sys", "")
test = ['cut '+knife+' off for fuged,', 'cut '+knife+' off,', 'cut '+knife+' fool alabala,', 'cut '+knife+' nieh,', 'prrra '+knife+' alabala,',
'cut '+knife+' fuged streaming,', 'cut '+knife+' alabala fuged,', 'cut '+knife+' off alabala,', 'prrra '+knife+' fool alabala,',
'cut '+knife+' off fuged,', 'prrra '+knife+' niether alabala,', 'cut off '+knife+' for fuged,' 'cut '+knife+' fuged fool alabala,',
'cut '+knife+' off niether,', 'where to cut '+knife+',', ''+knife+' fool alabala off,', 'steel '+knife+' off fuged,', 'cut '+knife+' fuged niether,',
''+knife+' fool alabala off,', 'fuged streaming '+knife+',', 'cut '+knife+' niether,', 'cut '+knife+' fuged,', 'red '+knife+' off,', ''+knife+' off,',
'red '+knife+',', 'cut '+knife+',', ''+knife+' fuged,', 'fuged '+knife+',', ''+knife+' off,', 'off '+knife+',', ''+knife+',']
random.shuffle(test)
scris = [x for x in test if len(x) <= 30]
row_test.append(scris) #row_test.append(scris[0])
fisier_text_knife.writerow(row_test)
如果我用它替换row_test.append(scris[0:7])
它,row_test.append(scris[0])
它只写一个字符串(但写它时不带括号--> [] <--)。
我想写七八行。我在这段代码上浪费了我的大脑。
谢谢你的时间。