Created
December 21, 2010 00:22
-
-
Save TkTech/749286 to your computer and use it in GitHub Desktop.
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
# encoding: utf-8 | |
# | |
# enum.py | |
# pymc | |
# | |
# Created by Tyler Kennedy on 2010-12-20. | |
# Copyright 2010 Tyler Kennedy. All rights reserved. | |
# | |
class Enum(object): | |
def __init__(self, dct): | |
object.__setattr__(self, 'data', dct) | |
def __getattr__(self, attr): | |
if attr in self.data: | |
return self.data[attr] | |
else: | |
raise AttributeError() | |
def __setattr__(self, attr, value): | |
raise RuntimeError('You cannot modify this object!') | |
def __contains__(self, item): | |
return item in self.data | |
def __iter__(self): | |
return self.data.__iter__() | |
def items(self): | |
return self.data.items() | |
def get_name(self, value): | |
for k,v in self.data.items(): | |
if v == value: | |
return k | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment