[Tutor] Unexpected results with obj.method().method()
C M Caine
cmcaine at googlemail.com
Mon Dec 10 15:43:38 CET 2012
Thanks eryksun, that was the bug. Thanks for pointing out the tabs as well,
they were added by vim's autoindent. I've set expandtab for python files
now.
I decided to change the code such that current_player and turn_number are
hidden behind properties meaning I won't overwrite them accident or
stupidity later.
On 6 December 2012 01:31, eryksun <eryksun at gmail.com> wrote:
> 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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121210/e0d9791b/attachment.html>
More information about the Tutor
mailing list