[Tutor] Why does the last loop not work?

Chris “Kwpolska” Warrick kwpolska at gmail.com
Tue Feb 25 11:26:35 CET 2014


On Tue, Feb 25, 2014 at 1:59 AM, Gregg Martinson
<gregg.martinson at gmail.com> wrote:
> # problem is that myTeams has no value outside of the loop
> for x in myTeams:
>     x.print_team

No, that is not the problem.  The problem is, you’re missing
parentheses there and are not executing the print_team method, just
referring to it.  Do this:

for x in myTeams:
    x.print_team()

This causes this output:

[kwpolska at kw-cassandra /tmp]% python foo.py
code is:  a
code is:  aa
code is:  b
code is:  bb
code is:  c
code is:  cc
code is:  d
team code is:  a
debated: team code is:  aa
debated: team code is:  b
debated: team code is:  bb
debated: team code is:  c
debated: team code is:  cc
debated: team code is:  d
debated: [kwpolska at kw-cassandra /tmp]%

Which is kinda wrong.   But that’s the fault of your print_team() and
lack of competitors.
-- 
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense


More information about the Tutor mailing list