第 0016 题: 纯文本文件 numbers.txt, 里面的内容(包括方括号)如下所示:
[ [1, 82, 65535], [20, 90, 13], [26, 809, 1024] ] 请将上述内容写到 numbers.xls 文件中,如下图所示:
numbers.xls
import json
import xlwt
wb = xlwt.Workbook()
ws = wb.add_sheet('numbers')
with open('D:\工作\python\项目--1') as f:
content = f.read()
json = json.loads(content)
i = 0
for con in json:
j = 0
for item in con:
print(item)
ws.write(i, j, item)
j += 1
i += 1
wb.save('D:\工作\python\项目--1')