|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- # -*- coding:utf8 -*-
- class AthleteList(list):
- """
- 初始化类属性
- name:运动员姓名
- birth:运动员出生日期
- time:时间成绩
- """
- def __init__(self, name, birth=None, times=[]):
- list.__init__([])
- self.name = name
- self.birth = birth
- self.times = times
- self.extend(times)
- def santize(self):
- if "-" in self:
- splitter = "-"
- if ":" in self:
- splitter = ":"
- else:
- return self
- (mins, secs) = self.split(splitter)
- return mins + "." + secs
- def top3(self):
- return print(sorted(set([self.santize(t) for t in self]))[0:3])
- def get_coach_data(filename):
- try:
- with open(filename, "r") as file:
- data = file.read()
- except IOError as file_err:
- print("{0}".format(file_err))
- else:
- tmp = data.strip().split(",")
- return AthleteList(tmp.pop(0), tmp.pop(0),tmp)
- if __name__ == "__main__":
- james = get_coach_data("james2.txt")
- james.top3()
复制代码
求问各位大佬,为什么会报错:
- D:\python练习\venv\Scripts\python.exe D:/python练习/Head_First_Python/第六章_定制数据_打包代码和数据/AthleteList.py
- Traceback (most recent call last):
- File "D:/python练习/Head_First_Python/第六章_定制数据_打包代码和数据/AthleteList.py", line 43, in <module>
- james.top3()
- File "D:/python练习/Head_First_Python/第六章_定制数据_打包代码和数据/AthleteList.py", line 29, in top3
- return print(sorted(set([self.santize(t) for t in self]))[0:3])
- File "D:/python练习/Head_First_Python/第六章_定制数据_打包代码和数据/AthleteList.py", line 29, in <listcomp>
- return print(sorted(set([self.santize(t) for t in self]))[0:3])
- TypeError: santize() takes 1 positional argument but 2 were given
复制代码
我传入sanitize的参数明明是一个数据啊,为什么报错会是两个 |
|