@@ -87,33 +87,29 @@ def append(self, target):
87
87
88
88
ring = RingSort ()
89
89
90
- f_zip = ZipFile ('people.zip' )
91
- f_csv = TextIOWrapper (f_zip .open ('people.csv' ))
92
- data = reader (f_csv )
93
- for line in data :
94
- name = line [0 ]
95
- age = line [1 ]
96
- ring .append (Person (name , age ))
97
- 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()
107
-
108
- # f_txt = open("people.txt")
109
- # for line in f_txt:
110
- # if line.count(',') != 1:
111
- # raise IOError("格式错误")
112
- # line = line.strip('\n')
113
- # name = line.split(',')[0]
114
- # age = line.split(',')[1]
115
- # ring.append(Person(name, age))
116
- # f_txt.close()
90
+ with ZipFile ('people.zip' ) as f_zip :
91
+ with TextIOWrapper (f_zip .open ('people.csv' )) as f_csv :
92
+ data = reader (f_csv )
93
+ for line in data :
94
+ name = line [0 ]
95
+ age = line [1 ]
96
+ ring .append (Person (name , age ))
97
+
98
+ # with open("people.csv") as f_csv:
99
+ # data = reader(f_csv)
100
+ # for line in data:
101
+ # name = line[0]
102
+ # age = line[1]
103
+ # ring.append(Person(name, age))
104
+
105
+ # with open("people.txt") as f_txt:
106
+ # for line in f_txt:
107
+ # if line.count(',') != 1:
108
+ # raise IOError("格式错误")
109
+ # line = line.strip('\n')
110
+ # name = line.split(',')[0]
111
+ # age = line.split(',')[1]
112
+ # ring.append(Person(name, age))
117
113
118
114
try :
119
115
start = int (input ("\n Please input a starting position:" ))
0 commit comments