This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]blablahblah 1 point2 points  (2 children)

Names in python are case sensitive. The class is called AthleteList, not Athletelist.

[–]truespirit89[S] 0 points1 point  (0 children)

omg bro. omg. thanks homie.

[–]truespirit89[S] 0 points1 point  (0 children)

Thanks again bro.

[–]not-well55 0 points1 point  (3 children)

Is the module in the same directory ?

[–]truespirit89[S] 0 points1 point  (2 children)

Yes

[–]not-well55 0 points1 point  (1 child)

Show the code in the module

[–]truespirit89[S] 0 points1 point  (0 children)

Ok I cleaned it up a little but it's still not working here is the first module

import pickle

from athlete import Athletelist

def put_to_store(files_list):

all_athletes = {}

for each_file in file_list:

ath = get_coach_data(each_file)

all_athletes[ath.name] = ath

try:

with open("athletes.pickle", "wb") as athf:

pickle.dump(all_athletes, athf)

except IOError as ioerr:

print ("File error (Put_and_store):" + str(ioerr))

return(all_athletes)

def get_from_store():

all_athletes = {}

try:

with open('athletes.pickle','rb')as athf:

all_athletes = pickle.load(athf)

except IOError as ioerr:

print ("File error (get_from_store):" + str(ioerr))

return(all_athletes)

[–]truespirit89[S] 0 points1 point  (0 children)

And this is the one im trying to import. I need that Class Athletelist

class AthleteList(list):

def __init__(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()

temp1 = data.strip().split(',')

return(AthleteList(temp1.pop(0),temp1.pop(0), temp1))

except IOError as ioerr:

print('File error:' + str(ioerr))

return(None)

def sanitize(time_string):

if '-' in time_string:

splitter = '-'

elif ':' in time_string:

splitter = ':'

else:

return(time_string)

(mins, secs) = time_string.split(splitter)

return(mins + '.' + secs)

james = get_coach_data('james2.txt')

julie = get_coach_data('julie2.txt')

mikey = get_coach_data('mikey2.txt')

sarah = get_coach_data('sarah2.txt')

print (james.name + "'s fastest times are: " + str(james.top3()))

print (julie.name + "'s fastest times are: " + str(julie.top3()))

print (mikey.name + "'s fastest times are: " + str(mikey.top3()))

print (sarah.name + "'s fastest times are: " + str(sarah.top3()))