def sanitize(time_string):
if "-" in time_string:
splitter = "_"
elif ":" in time_string:
splitter = ":"
else:
return time_string
(mins, secs) = time_string.strip().split(splitter)
return mins, ".", secs
class AthleteList(list):
def int(self, a_name, a_dob=None, a_times=[]):
list.__init__([])
self.name = a_name
self.dob = a_dob
self.extend(a_times)
def top3(self):
return sorted(set([sanitize(t) for t in self]))[0:3]
def get_coach_data(filename):
try:
with open(filename) as f:
data = f.readline()
templ = data.strip().split(",")
return AthleteList([templ.pop(0), templ.pop(0), templ])
except IOError as ioerr:
print "File error: ", str(ioerr)
return None
sarah = get_coach_data("sarah2.txt")
print sarah.name, "'s fastest times are: ", str(sarah.top3())
错误提示:
Traceback (most recent call last):
File "C:\Python27\listclass2.py", line 30, in
sarah = get_coach_data("sarah2.txt")
File "C:\Python27\listclass2.py", line 25, in get_coach_data
return AthleteList(templ.pop(0), templ.pop(0), templ)
TypeError: list() takes at most 1 argument (3 given)
不知道怎么改。。