sinat_28458775 2015-05-29 14:39 采纳率: 50%
浏览 2119

继承python内置的list,在创建实例时,提示参数个数不正确

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)

不知道怎么改。。

  • 写回答

3条回答 默认 最新

  • oyljerry 2015-05-29 15:06
    关注

    提示没有这个属性name。

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站