Created
November 12, 2008 15:27
-
-
Save gvx/24186 to your computer and use it in GitHub Desktop.
Immutable objects made mutable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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