[Tutor] Criticism / Suggestions

Kent Johnson kent37 at tds.net
Thu Mar 3 13:01:33 CET 2005


Bill Kranec wrote:
> Hi Kent,
> 
> First off, thank you so much for the suggestions!  They have helped 
> clarify some of the concepts I've been struggling with lately ( mostly 
> object - related ones ).  I have been teaching myself Python in my spare 
> time for the last few months, and have no previous programming 
> experience, so any feedback I get really helps me improve as a programmer.
> 
> I have implemented some of the changes you talked about, and posted an 
> updated version of my program here:
> 
> http://rafb.net/paste/results/SicsjJ23.html
> 
> I hope this new version is a bit better, and that my answers to your 
> questions help you understand what I'm doing.

OK, some comments on the code.

- I would make checkTeammates() and checkOpponents() return a boolean value rather than raising an 
exception. Then next() would have code like
   if self.checkTeammates( self.flattened ) and self.checkOpponents( self.flattened ):
     # add the round to the tournament
   else:
     # handle a bad round

- You are (ab)using the iterator protocol essentially to implement a while loop. I would rename 
next() to something like makeTournament() and put the code in a loop like
   while len(self.rounds) < 11:
     ...

You can return the final tournament if you want or just have the output from makeTournament() be the 
only result.

- Instead of
   stdout.write( str( self.key ) + '\n' )
just use
   print self.key

BTW what is magic about 113400?

Kent





More information about the Tutor mailing list