unittest.TestCase, lambda and __getitem__

Alex Martelli aleaxit at yahoo.com
Tue Sep 14 10:43:30 EDT 2004


Scott David Daniels <Scott.Daniels at Acm.Org> wrote:

> Roy Smith wrote:
> >.... I think you need to just create a little function and call it:
> > 
> > def tryIndex (object, index):
> >    return obj [index]
> 
> For python 2.4 and beyond, the function is called operator.getitem,
> so I'd call it getitem.

It's named just the same way in 2.3:

kallisti:~ alex$ python2.3
Python 2.3 (#1, Sep 13 2003, 00:49:11) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import operator
>>> operator.getitem
<built-in function getitem>
>>> 

What's new in 2.4 is operator.itemgetter, a subtle higher-order
function...


Alex



More information about the Python-list mailing list