所以我想从列表中拆分字符串到多个列表中 像行[1]应该被拆分成列表m中包含的另一个列表 我在这里看到了它,它可以被访问m [0] [0]从第一个列表中获得第一个项目。 导入CSVCSV将行拆分成列表
reader = csv.reader(open("alerts.csv"), delimiter=',')
)
rows=[]
for row in reader:
rows.append(row)
num_lists=int(len(rows))
lists=[]
m=[]
for x in rows:
m.append(x.split(';')[0])
印刷行:
[['priority;status;time;object_class;host;app;inc;tool;msg'], ['P2;CLOSED;24-09-2016 20:06:41;nm;prod;;390949;HPNNM;call'], ['P2;CLOSED;24-09-2016 20:06:41;nm;prod;;390949;HPNNM;msg'], ['P2;CLOSED;24-09-2016 20:06:41;nm;prod;;390949;HPNNM;msg']]
和输出应该看起来像 M [0] [0]应该返回pririty
将您的分隔符更改为'';''(脚本的第一行) – jbndlr