[Tutor] Improving My Simple Game Code for Speed, Memory and Learning
WolfRage
wolfrage8765 at gmail.com
Tue Jan 13 00:33:27 CET 2015
On 01/12/2015 05:00 PM, Alan Gauld wrote:
<SNIP>
> Sorry, no time to read the detail, but one thing I thought might be
> handy is to convert the draw method to return a string and make it the
> __str__methodf of the grid.
> Then the draw method becomes print(self)
>
> And you can also just use print(aGrid) etc.
>
> Something like (untested):
>
> def __str__(self):
> output = []
> for row in self.transposed_grid:
> s='| '
> for node in row:
> s += (str(node) + ' | ')
> output.append(s)
> return '\n'.join(output)
>
> def draw(self): print (self)
>
>
> Just a thought.
>
OK. I will implement this, thanks. It goes well with the __str__ method
of the tiles/nodes.
More information about the Tutor
mailing list