Skip to content

Instantly share code, notes, and snippets.

@gvx
Created November 12, 2008 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gvx/24186 to your computer and use it in GitHub Desktop.
Save gvx/24186 to your computer and use it in GitHub Desktop.
Immutable objects made mutable
#By Robin Wellner (gvx)
#I hereby waive copyright and related or neighboring rights to this work
#See the Creative Commons Zero Waiver at <http://creativecommons.org/publicdomain/zero/1.0/>
class mutable(object):
def __init__(self, obj):
self._obj = obj
def __repr__(self):
return 'mutable('+repr(self._obj)+')'
def __call__(self, obj=None):
oldobj = self._obj
if obj is not None:
self._obj = obj
return oldobj
def __getattr__(self, name):
return self._obj.__getattribute__(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment