def get_coach_data(filename): #(2)文件进入这个方法 try: with open(filename) as f: #(3)读取文件存成 f data = f.readline() #(4)data等于 读取f一行 temp = data.strip().split(',') #(5)在temp中strip==>删除空格 split 用逗号分割字符串 return (player_list(temp.pop(0), temp.pop(0), temp)) #(6) 用return 进入(7) 最后走一圈 把值传回get_coach_data方法 except IOError as ioerr: print("File error (get_coach_data):" + str(ioerr)) return (None)
#coding:utf-8 from CLASS_playerlist import player_list #从CLASS_playerlist文件 里引用class player_list 两个文件必须在同级 vatini = player_list("Vatini") vatini.append('1.55') print (vatini.top3()) vatini.extend(['999.888' , "1:22" , "2-99", "0.95"]) print (vatini.top3())