forked from Show-Me-the-Code/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (39 loc) · 975 Bytes
/
main.py
File metadata and controls
55 lines (39 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding:utf-8 -*-
'''
纯文本文件 numbers.txt, 里面的内容(包括方括号)如下所示:
[
[1, 82, 65535],
[20, 90, 13],
[26, 809, 1024]
]
请将上述内容写到 numbers.xls 文件中,如下图所示:
@Author monkey
@Date 2017-8-31
'''
import json
import xlwt
def getNumber():
with open('numbers.txt', 'r', encoding='UTF-8') as file:
text = ''
for line in file:
text = text + line
number_json = json.loads(text, encoding = 'UTF-8')
print(number_json)
writeInXLS(number_json)
def writeInXLS(list):
fileName = 'numbers.xls'
# 创建 文件
file = xlwt.Workbook()
# 创建 表
sheet = file.add_sheet('numbers', cell_overwrite_ok=True)
row = 0
col = 0
for l in list:
for i in l:
sheet.write(row, col, i)
col += 1
row += 1
col = 0
file.save(fileName)
if __name__ == '__main__':
getNumber()