[Tutor] Improving My Simple Game Code for Speed, Memory and Learning
Alan Gauld
alan.gauld at btinternet.com
Mon Jan 12 23:00:00 CET 2015
On 12/01/15 20:28, WolfRage wrote:
> anyone has any improvements or things to think about, I would love to
> hear it.
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.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list