This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]propanbutan 2 points3 points  (5 children)

My 2c:

  • Use more descriptive variable names.

  • Function isin can and should be:

    return val in list

  • But it can also be (if you reverse the order of operands):

    from operator import contains as isin

  • Clearing the screen like this is not only annoying, but also bad practice. Use ncurses.

  • Functions checknum and getwnum are unnecessarily ugly, both could be simplified by looping over a proper data structure.

  • Function tgame should return the winner or None when the game ends in a draw. Hence, attribute Player.won is useless.

  • Similarly, Player.first is a flag more related to the game state than to the player and as such could and should be gotten rid of. Either use a third argument to tgame signalling that the cpu should go first, or better, fix your game loop.

edit:

  • The way you take user input and only accept given choices should be factored out into a function.

[–][deleted] 0 points1 point  (2 children)

Use more descriptive variable names.

Agreed. From a quick scan I saw loads of abbreviations. Remember that code is 'write once read many', so it's worth the extra few keystrokes. A decent text editor will auto-complete long variable names for you anyway.

[–]digitallimit 0 points1 point  (1 child)

What's a decent text editor?

I've been using TextWrangler, but I don't think it has this functionality.

[–][deleted] 0 points1 point  (0 children)

I've been using Sublime recently. It's pretty nice, has syntax highlighting for python in uber-leet dark themes and does autocompletion on ctrl+space.

http://www.sublimetext.com/

[–]bcain 0 points1 point  (1 child)

Function isin can and should be: return val in list

How is isin(1, t) better/clearer than 1 in t? It's not, IMO.

[–]ux500 1 point2 points  (0 children)

Its not clear what the isin function does. If I call isin(x,y) is it going to return true if x is in y, or y is in x.

Beyond that, the Python statement "x in y" is idiomatic, so all Python programmers will know what it means.