[Tutor] Unexpected results with obj.method().method()

eryksun eryksun at gmail.com
Thu Dec 6 02:31:20 CET 2012


On Wed, Dec 5, 2012 at 1:11 PM, C M Caine <cmcaine at googlemail.com> wrote:
>
> The full code is on pastebin http://pastebin.com/tUh0W5Se
>
>>>> import game
>>>> S = game.State()
>>>> S1 = S.move_state(1).move_state("SWAP")
>>>> S2 = S.move_state(1)
>>>> S3 = S2.move_state("SWAP")
>>>> S1 == S3
> False

In lines 156-160 you change players by mutating the object. You need
to use a local variable such as "next_player" and return State(board,
self.turn_number + 1, next_player).

Also, you're mixing tabs and 2-space indents. Please choose one or the
other. The most popular style is 4-space indents, as recommended by
the PEP 8 style guide.


More information about the Tutor mailing list