Skip to content

Commit 9e92f54

Browse files
committed
添加 zip 文件,导入对象数据
1 parent 54a106b commit 9e92f54

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

josephus.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
__author__ = 'Chongsen Zhao'
77

88
from csv import reader
9+
from zipfile import ZipFile
10+
from io import TextIOWrapper
911

1012

1113
class Person:
@@ -85,13 +87,23 @@ def append(self, target):
8587

8688
ring = RingSort()
8789

88-
f_csv = open("people.csv")
90+
f_zip = ZipFile('people.zip')
91+
f_csv = TextIOWrapper(f_zip.open('people.csv'))
8992
data = reader(f_csv)
9093
for line in data:
9194
name = line[0]
9295
age = line[1]
9396
ring.append(Person(name, age))
9497
f_csv.close()
98+
f_zip.close()
99+
100+
# f_csv = open("people.csv")
101+
# data = reader(f_csv)
102+
# for line in data:
103+
# name = line[0]
104+
# age = line[1]
105+
# ring.append(Person(name, age))
106+
# f_csv.close()
95107

96108
# f_txt = open("people.txt")
97109
# for line in f_txt:

people.zip

194 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)