当我尝试运行此代码时,我在定义get_coach_data函数的行中收到语法错误。我试图在没有进口泡菜的情况下运行,而且效果很好。
import pickle
def sanitize(time_string):
if '-' in time_string:
splitter='-'
elif ': in time_string':
splitter=':'
else:
return(time_string)
(mins,secs)= time_string.split(splitter)
return(mins+'.'+secs)
class Athlete:
def __init__(self, a_name, a_dob=None, a_times=[]):
self.name = a_name
self.dob = a_dob
self.times = a_times
def top3(self):
return(sorted(set([sanitize(t) for t in self.times]))[0:3])
def get_coach_data(filename):
try:
with open(filename) as f:
data = f.readline()
templ = data.strip().split(',')
return({'Name' : templ.pop(0),
'DOB' : templ.pop(0),
'Times': str(sorted(set([sanitize(t) for t in templ]))[0:3])})
except IOError as ioerr:
print('File error: ' + str(ioerr))
return(None)