I am trying to generate a list of teams using objects that I collect into a list that I can cycle through. But when I run the last loop there is nothing produced. I am pretty sure it has to do with my syntax for the list and the substitution of a a local variable but I can't figure out how to make it work. Any help would be appreciated. I am working my way though *Learning Python*, but its a long slog.
#!/usr/bin/env python def printit (aff,neg): print (aff, "\t",neg,"\tTBD\tTBD") def header (r): print ("##############################") print ("### Round: ",r," ####") print ("##############################") print ("Aff\tNeg\tJudge\tRoom") class Team(object): code = "" # The class "constructor" - It's actually an initializer def __init__(self,code): self.code = code print ("code is: ",code) self.competitors=[] def print_team(self): print("team code is: ",self.code) print("debated:",end=" ") for x in self.competitors: print (x) def debated(self,otherTeam): print (x) self.competitors.append(x) def giveCode(self): return self.code def make_team(code): team = Team(code) return team #MAIN Program# myTeamCodes=["a","aa","b","bb","c","cc","d"] # Make teams myTeams=[]#list of teams for x in myTeamCodes: myteam=make_team(x) myTeams.append(myteam) # problem is that myTeams has no value outside of the loop for x in myTeams: x.print_team -- http://about.me/greggmartinson
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor