目前正在爲專有文件格式進行EDI轉換。輸入文件可能有數百到數千條記錄。每條線都是一條記錄。Python專有文件轉換循環
INFILE:(忽略開頭的空白行,它只是存在於視覺表現)
"1","2","3","4","5","6","7","can also contain text, and commas","9","10","11","12","13"
"1","2","3","4","5","6","7","can also contain text, and commas","9","10","11","12","13"
"1","2","3","4","5","6","7","can also contain text, and commas","9","10","11","12","13"
"1","2","3","4","5","6","7","can also contain text, and commas","9","10","11","12","13"
"1","2","3","4","5","6","7","can also contain text, and commas","9","10","11","12","13"
我需要一個循環,可以通過走行線,並從一列在原始文件複製數據,並粘貼轉換爲一個新文件,該文件將數據保存在不同的列中。有點像沒有列標題的vlookup。這裏是列號之間的關係。
InColumn-OutColumn
1-1, 2-2, 3-3, 4-4, 5-5, 6-6, 7-7, 8-8, 12-9, 14-10, 25-11, 68-24
在此先感謝,我似乎無法繞過這一個。
編輯:這裏要求的是我無法工作的破解代碼。
KEY = [1,2,3,4,5,6,7,8,12,14,25,68]
Body850 = open(TEMP, 'r+')
for line in Body850:
for x in line.split(','):
END += KEY[x]
print line
看起來像csv。 python有一個csv模塊來處理這種類型的文件 – njzk2
請提供一些你嘗試過的代碼,但是不起作用,所以我們可以幫你修復它。 –
好吧,我編輯了原文 – user2890953