Modifying the {} and [] tokens

Mel Wilson mwilson at the-wire.com
Thu Sep 11 22:07:33 EDT 2003


In article <Xns93F084E3691FDduncanrcpcouk at 127.0.0.1>,
Duncan Booth <duncan at NOSPAMrcp.co.uk> wrote:
>mwilson at the-wire.com (Mel Wilson) wrote in news:oQhU/ks/KXNd089yn at the-
>wire.com:
>>[ ... ]
>> where additive_identity is a magical value that's 0 working
>> with numbers, [] with lists, () with tuples and '' with
>> strings.  In real life I'd catch the key errors instead.
>
>FWIW, Your 'magical value' isn't actually terribly magical, it is easily
>defined with a few lines of Python:
>
>>>> class AdditiveIdentityClass:
>	def __coerce__(self, other):
>		return type(other)(), other

Cute!

        Thanks.         Mel.




More information about the Python-list mailing list