Skip to content

Commit 114e65f

Browse files
committed
Fix 0014-0016
1 parent f41a9dd commit 114e65f

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

Drake-Z/0014/0014.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def writeFlie(dictdata):
3636
worksheet.write(i, 0, label = num[i])
3737
for m in range(0, 4):
3838
worksheet.write(i, m+1, label = dictdata[num[i]][m])
39-
workbook.save('0014/student.xls')
39+
workbook.save('student.xls')
4040

4141
if __name__ == '__main__':
42-
file = open('0014/student.txt', 'r', encoding='utf-8')
42+
file = open('student.txt', 'r', encoding='utf-8')
4343
read_data(file.read())

Drake-Z/0015/0015.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ def writeFlie(dictdata, hangshu, lieshu):
3535
worksheet.write(i, 0, label = num[i])
3636
for m in range(0, lieshu):
3737
worksheet.write(i, m+1, label = dictdata[num[i]][m])
38-
workbook.save('0015/city.xls')
38+
workbook.save('city.xls')
3939

4040

4141

4242
if __name__ == '__main__':
43-
file = open('0015/city.txt', 'r', encoding='utf-8')
43+
file = open('city.txt', 'r', encoding='utf-8')
4444
hangshu = 3
4545
lieshu = 1
4646
re1 = '"(.*?)" :'

Drake-Z/0016/0016.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
'''第 0015 题: 纯文本文件 city.txt为城市信息, 里面的内容(包括花括号)如下所示:
5+
{
6+
"1" : "上海",
7+
"2" : "北京",
8+
"3" : "成都"
9+
}
10+
请将上述内容写到 city.xls 文件中。'''
11+
12+
__author__ = 'Drake-Z'
13+
14+
import os
15+
import re
16+
from collections import OrderedDict
17+
import xlwt
18+
19+
def shuju(data, re1, re2):
20+
c = OrderedDict([])
21+
re_xuhao = re.compile(r'%s' % re1)
22+
re_yuansu = re.compile(r'%s' % re2)
23+
a = re_xuhao.findall(data) #得到序号
24+
if len(a)==0:
25+
for d in range(0, hangshu):
26+
a.append(d)
27+
b = re_yuansu.findall(data) #得到具体数据
28+
for m, n in zip(a, b): #将数据转为Dict
29+
n = re.split(r',', n)
30+
c[m] = n
31+
writeFlie(c, hangshu, lieshu)
32+
33+
def writeFlie(dictdata, hangshu, lieshu):
34+
workbook = xlwt.Workbook(encoding = 'utf-8') #创建工作薄
35+
worksheet = workbook.add_sheet('My Worksheet') #创建表
36+
num = list(dictdata.keys()) #得到序号
37+
for i in range(0, hangshu):
38+
for m in range(0, lieshu):
39+
worksheet.write(i, m, label = dictdata[num[i]][m])
40+
workbook.save('numbers.xls')
41+
42+
43+
44+
45+
46+
if __name__ == '__main__':
47+
file = open('numbers.txt', 'r', encoding='utf-8')
48+
hangshu = 3
49+
lieshu = 3
50+
re1 = '%'
51+
re2 = '\[(.*?)\]'
52+
shuju(file.read(), re1, re2)

0 commit comments

Comments
 (0)