Skip to content

Instantly share code, notes, and snippets.

@nduhamel
Created December 20, 2010 20:48
Show Gist options
  • Save nduhamel/748954 to your computer and use it in GitHub Desktop.
Save nduhamel/748954 to your computer and use it in GitHub Desktop.
Simple Read-only dict python
import UserDict
class ReadOnlyDict(UserDict.IterableUserDict):
def __setitem__(self, key, item): raise TypeError
def __delitem__(self, key): raise TypeError
def clear(self): raise TypeError
def pop(self, key, *args): raise TypeError
def popitem(self): raise TypeError
def update(self, dict=None):
if dict is None:
pass
elif isinstance(dict, UserDict.UserDict):
self.data = dict.data
elif isinstance(dict, type({})):
self.data = dict
else:
raise TypeError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment