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 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题