使用Python

时间:2015-11-12 01:10:53

标签: python xlsxwriter

我有一个格式如下的文件:

2015-11-01|00:00:00|1
2015-11-02|23:00:00|11
2015-11-03|07:00:00|12
2015-11-04|09:00:00|20

我希望能够将这些行转换为列表格式,以便我可以执行以下字段:

for date, hour, count in arr:
       incoming_images.write(row, col, date)
       incoming_images.write(row, col + 1, hour)
       incoming_images.write(row, col + 2, count)
       row +=1

我需要帮助弄清楚如何制作这个" arr" (如果可能的话)。

1 个答案:

答案 0 :(得分:1)

Str = open("file").read()
lines =Str.count('\n')
Str= Str.replace('\n', '|')
words = Str.split("|")
for i in range(0,len(words)-1,3)
   date.append(words[i])
   hour.append(words[i+1])
   count.append(words[i+2])

for date, hour, count in zip(date,hour,count):
   incoming_images.write(row, col, date)
   incoming_images.write(row, col + 1, hour)
   incoming_images.write(row, col + 2, count)
   row +=1