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。

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型