Skip to content

Instantly share code, notes, and snippets.

@mikedouglas
Created June 26, 2012 20:10
Show Gist options
  • Save mikedouglas/2998579 to your computer and use it in GitHub Desktop.
Save mikedouglas/2998579 to your computer and use it in GitHub Desktop.
...
import types
class Object(object):
def __getitem__(self, key):
return 2*self.__getitem__(key)
obj = Object()
obj.__getitem__ = types.MethodType((lambda self, x: x), obj)
obj[5] #=> 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment