首页 新闻 会员 周边

james.top3()把top3()当成类的属性了,而不是我定义的函数怎么办???

0
[已解决问题] 解决于 2017-08-28 13:58
 1 def sanitize(time_string):
 2     if '-' in time_string:
 3         splitter = '-'
 4     elif ':' in time_string:
 5         splitter = ':'
 6     else :
 7         return (time_string)
 8     (mins,secs) = time_string.split(splitter)
 9     return (mins + '.' +secs)
10 
11 
12 class Athlete:
13     def __init__(self,a_name,a_dob=None,a_times=[]):
14         self.name = a_name
15         self.dob = a_dob
16         self.times = a_times
17 
18 
19 
20 def get_coach_data (filename):
21     try:
22         with open (filename) as f:
23             data =f.readline()
24         templ = data.strip().split(',')
25         return(Athlete(templ.pop(0),templ.pop(0),templ))
26     except IOError as ioerr:
27         print('File Error' + str(ioerr))
28         return(None)
29 
30 def top3(self):
31     return(sorted(set([sanitize(t) for t in self.times]))[0:3])
32 
33 james = get_coach_data('james2.txt')
34 print(james.name)
35 print(james.times)
36 print(str(james.top3()))

Traceback (most recent call last):
File "C:/Lib/idlelib/12.py", line 36, in <module>
print(str(james.top3()))
AttributeError: 'Athlete' object has no attribute 'top3'

dang幸福来敲门的主页 dang幸福来敲门 | 初学一级 | 园豆:177
提问于:2017-08-27 17:41
< >
分享
最佳答案
0

格式不对,top3()应该有缩进。。

dang幸福来敲门 | 初学一级 |园豆:177 | 2017-08-27 22:48
其他回答(2)
0

格式不对吧。应该是有缩进的

fcyh | 园豆:568 (小虾三级) | 2017-08-28 09:17
0

写Python竟然没使用游标卡尺(你要把top3提到类Athlete中吧?)

MrNice | 园豆:3450 (老鸟四级) | 2017-08-28 10:51

是的。没注意到格式问题

支持(0) 反对(0) dang幸福来敲门 | 园豆:177 (初学一级) | 2017-08-28 13:59
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册