New-style classes and special methods

Carl Banks imbosol-1046106958 at aerojockey.com
Mon Feb 24 18:38:33 CET 2003


Andrew Bennetts wrote:
> On Mon, Feb 24, 2003 at 07:13:44AM +0000, Carl Banks wrote:
>> Jp Calderone wrote:
>> > [-- text/plain, encoding quoted-printable, 37 lines --]
>> > 
>> >  Consider this class:
>> > 
>> >    class Foo:
>> >        def __getattr__(self, name):
>> >            return lambda arg: arg
>> > 
>> >  It can be used thusly:
>> > 
>> >    f = Foo()
>> >    print f[10]
>> 
>> Sure?
> 
>    >>> class Foo:
>    ...     def __getattr__(self, name):
>    ...         return lambda arg: arg
>    ... 
>    >>> f = Foo()
>    >>> print f[10]
>    10
> 
> Yep, I'd say he's sure.


D'oh.  The trickery escaped me.


-- 
CARL BANKS





More information about the Python-list mailing list