File tree Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Original file line number Diff line number Diff line change 5
5
6
6
__author__ = 'Chongsen Zhao'
7
7
8
+ from csv import reader
9
+
8
10
9
11
class Person :
10
12
"""Summary of class here.
@@ -82,15 +84,24 @@ def append(self, target):
82
84
if __name__ == '__main__' :
83
85
84
86
ring = RingSort ()
85
- f_txt = open ("people.txt" )
86
- for line in f_txt :
87
- if line .count (',' ) != 1 :
88
- raise IOError ("格式错误" )
89
- line = line .strip ('\n ' )
90
- name = line .split (',' )[0 ]
91
- age = line .split (',' )[1 ]
87
+
88
+ f_csv = open ("people.csv" )
89
+ data = reader (f_csv )
90
+ for line in data :
91
+ name = line [0 ]
92
+ age = line [1 ]
92
93
ring .append (Person (name , age ))
93
- f_txt .close ()
94
+ f_csv .close ()
95
+
96
+ # f_txt = open("people.txt")
97
+ # for line in f_txt:
98
+ # if line.count(',') != 1:
99
+ # raise IOError("格式错误")
100
+ # line = line.strip('\n')
101
+ # name = line.split(',')[0]
102
+ # age = line.split(',')[1]
103
+ # ring.append(Person(name, age))
104
+ # f_txt.close()
94
105
95
106
try :
96
107
start = int (input ("\n Please input a starting position:" ))
Original file line number Diff line number Diff line change
1
+ "Jorn ",25
2
+ "Tom ",30
3
+ "Jerry ",35
4
+ "Mike ",40
You can’t perform that action at this time.
0 commit comments