<div dir="ltr">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 <u>Learning Python</u>, but its a long slog. <div>
<br></div><div><div>#!/usr/bin/env python</div><div>def printit (aff,neg):</div><div> print (aff, "\t",neg,"\tTBD\tTBD")</div><div><br></div><div>def header (r):</div><div> print ("##############################")</div>
<div> print ("### Round: ",r," ####")</div><div> print ("##############################")</div><div> print ("Aff\tNeg\tJudge\tRoom")</div><div><br></div><div><br>
</div><div><br></div><div><br></div><div>class Team(object):</div><div> code = ""</div><div> </div><div><br></div><div><br></div><div><br></div><div> # The class "constructor" - It's actually an initializer </div>
<div> def __init__(self,code):</div><div> self.code = code</div><div> print ("code is: ",code)</div><div> self.competitors=[]</div><div> def print_team(self):</div><div> print("team code is: ",self.code)</div>
<div> print("debated:",end=" ")</div><div> for x in self.competitors:</div><div> print (x)</div><div><br></div><div> def debated(self,otherTeam):</div><div> print (x)</div>
<div> self.competitors.append(x)</div><div> def giveCode(self):</div><div> return self.code</div><div> </div><div><br></div><div>def make_team(code):</div><div> team = Team(code)</div><div> return team</div>
<div><br></div><div>#MAIN Program#</div><div>myTeamCodes=["a","aa","b","bb","c","cc","d"]</div><div># Make teams</div><div>myTeams=[]#list of teams</div>
<div>for x in myTeamCodes:</div><div> myteam=make_team(x)</div><div> myTeams.append(myteam)</div><div># problem is that myTeams has no value outside of the loop </div><div>for x in myTeams:</div><div> x.print_team</div>
<div>--<br><a href="http://about.me/greggmartinson" target="_blank">http://about.me/greggmartinson</a></div>
</div></div>