我在窗體中的txt文件中有數據。製表符分隔的數據將列讀取爲列表
here
a b c
e f g
tere
x y z
w t y
我需要將列讀入列表。像
col1 = ['here', '', '', tere, '', '']
col2= ['', 'a', 'e', '', 'x'.'w']
等等。
我用
import re
infile = open('text.txt', 'r')
i=0
a0='';a1='';a2='';a3='';a4='';a5='';a6='';a7='';
for line in infile:
[a1[i],a2[i],a3[i],a4[i],a5[i],a6[i],a7[i],a8[i]] = line.split('\t')
i+=1
它說,「海峽」對象不支持的項目分配。
任何提示?
你應該保持適當的位置,但要以適合你的數據的方式使用它,以便正確地刪除換行符。考慮.rstrip('\ n')只能刪除該行右側的換行符。 – sage88