interesting bound-built-in-method technique

Chris Ryland cpr at emsoftware.com
Thu Jan 18 11:46:01 EST 2001


Reading the Quixote sources taught me an interesting little "hack"
using bound-built-in methods:

>>> m = {'foo': 1, 'bar': 0}.has_key
>>> m('foo')
1
>>> m('bar')
0

Is this a common idiom in Python? Very clever for turning a dictionary
lookup into a functional form.

Are there other clever but generally obscure idia? (Idioms? ;-)
--
Chris Ryland * Em Software, Inc. * www.emsoftware.com


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list