zoukankan      html  css  js  c++  java
  • AttributeError: 'Athlete' object has no attribute 'top3'

    Traceback (most recent call last):
    File "C:Libidlelib13.py", line 40, in <module>
    print (james.top3())
    AttributeError: 'Athlete' object has no attribute 'top3'

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

    修改错误的方法    :

    1 class Athlete:
    2     def __init__ (self,a_name,a_dob = None,a_times =[]):
    3         self.name = a_name
    4         self.dob = a_dob
    5         self.times  = a_times
    6 
    7     def top(self):
    8         return(sorted(set([sanitize(t) for t in self.times]))[0:3])

    def top3(self) 前面加Tab

    格式!!!

  • 相关阅读:
    HTML&&CSS
    web概述&HTML快速入门
    JDBC连接池&JDBCTemplate
    基于Breast Cancer dataset的决策树分类及可视化
    三维数组按行优先存储求某位置的地址
    2019年复旦计算机专硕考研经验总结
    1013 Battle Over Cities (25 分)
    1009 Product of Polynomials (25 分)
    1004 Counting Leaves (30 分)
    1090 危险品装箱 (25 分)
  • 原文地址:https://www.cnblogs.com/xflqm/p/7441966.html
Copyright © 2011-2022 走看看