Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Let PgnFile implement more container methods.

  • Loading branch information...
commit 766dd2e75a2b93296c64b95e9601536a9f28cea1 1 parent ce32837
@niklasf authored
Showing with 19 additions and 2 deletions.
  1. +19 −2 chess/pgn_file.py
View
21 chess/pgn_file.py
@@ -11,8 +11,25 @@ def add_game(self, game):
def __len__(self):
return len(self._games)
- def __getitem__(self, index):
- return self._games[index]
+ def __getitem__(self, key):
+ return self._games[key]
+
+ def __setitem__(self, key, value):
+ self._games[key] = value
+
+ def __delitem__(self, key):
+ del self._games[key]
+
+ def __iter__(self):
+ for game in self._games:
+ yield game
+
+ def __reversed__(self):
+ for game in reversed(self._games):
+ yield game
+
+ def __contains__(self, game):
+ return game in self._games
@classmethod
def open(cls, path):
Please sign in to comment.
Something went wrong with that request. Please try again.