Skip to content

Commit 481473d

Browse files
author
yincongxian
committed
Add the Solution to 0016.
1 parent 7a05d95 commit 481473d

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

renzongxian/0016/0016.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
2+
# Author:renzongxian
3+
# Date:2014-12-22
4+
# Python 3.4
5+
6+
"""
7+
8+
第 0016 题: 纯文本文件 numbers.txt, 里面的内容(包括方括号)如下所示:
9+
[
10+
[1, 82, 65535],
11+
[20, 90, 13],
12+
[26, 809, 1024]
13+
]
14+
请将上述内容写到 numbers.xls 文件中.
15+
16+
"""
17+
18+
import xlwt3
19+
import json
20+
21+
22+
def write_txt_to_xls(txt_file):
23+
# Read form the txt file
24+
txt_object = open(txt_file, 'r')
25+
file_content = json.load(txt_object)
26+
27+
# Write to the xls file
28+
xls_object = xlwt3.Workbook()
29+
sheet = xls_object.add_sheet('numbers')
30+
for i in range(len(file_content)):
31+
data = file_content[i]
32+
for j in range(len(data)):
33+
sheet.write(i, j, data[j])
34+
xls_object.save('numbers.xls')
35+
36+
37+
if __name__ == '__main__':
38+
write_txt_to_xls('numbers.txt')
39+

renzongxian/0016/numbers.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
[1, 82, 65535],
3+
[20, 90, 13],
4+
[26, 809, 1024]
5+
]

0 commit comments

Comments
 (0)