我在窗体中的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