diff options
author | luke@maurits.id.au <luke@maurits.id.au@0f58610c-415a-11de-9c03-5d6cfad8e937> | 2012-05-02 01:12:49 +0000 |
---|---|---|
committer | luke@maurits.id.au <luke@maurits.id.au@0f58610c-415a-11de-9c03-5d6cfad8e937> | 2012-05-02 01:12:49 +0000 |
commit | d97a00a8c72ee9044b2f248ca3025ca098a0e06f (patch) | |
tree | dab879a2657d2aa0ee59fa5210ad45a0b9356432 | |
parent | 618b7c961e1165f81a178707acb20d252aef268e (diff) | |
download | python-prettytable-d97a00a8c72ee9044b2f248ca3025ca098a0e06f.tar.gz |
Reimplemented slicing with __getitem__ instead of __getslice__
git-svn-id: http://prettytable.googlecode.com/svn/trunk@53 0f58610c-415a-11de-9c03-5d6cfad8e937
-rw-r--r-- | src/prettytable.py | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/prettytable.py b/src/prettytable.py index d1f0d73..c4ca03f 100644 --- a/src/prettytable.py +++ b/src/prettytable.py @@ -159,16 +159,15 @@ class PrettyTable(object): else: raise AttributeError(name) - def __getslice__(self, i, j): - """Return a new PrettyTable whose data rows are a slice of this one's - - Arguments: - - i - beginning slice index - j - ending slice index""" + def __getitem__(self, index): newtable = copy.deepcopy(self) - newtable._rows = self._rows[i:j] + if isinstance(index, slice): + newtable._rows = self._rows[index] + elif isinstance(index, int): + newtable._rows = [self._rows[index],] + else: + raise Exception("Index %s is invalid, must be an integer or slice" % str(index)) return newtable def __str__(self): |