Created
December 20, 2010 20:48
-
-
Save nduhamel/748954 to your computer and use it in GitHub Desktop.
Simple Read-only dict python
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
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