Permalink
Browse files

Let PgnFile implement more container methods.

  • Loading branch information...
1 parent ce32837 commit 766dd2e75a2b93296c64b95e9601536a9f28cea1 @niklasf committed Oct 9, 2012
Showing with 19 additions and 2 deletions.
  1. +19 −2 chess/pgn_file.py
View
@@ -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):

0 comments on commit 766dd2e

Please sign in to comment.