Example #1
0
 def __getattr__(self, item):
     try:
         return OrderedDict.__getattribute__(self, item)
     except AttributeError:
         try:
             return self.__getitem__(item)
         except KeyError:
             try:
                 return self.__getitem__(item.replace("-", "_"))
             except KeyError:
                 raise AttributeError("'%s' object has no attribute '%s'", (self.__class__.__name__, item))
Example #2
0
class AutoIncDict:
    def __init__(self):
        self.__d = OrderedDict()

    def __getitem__(self, key):
        if key not in self.__d:
            self.__d[key] = len(self.__d)
        return self.__d[key]

    def __getattr__(self, attr):
        try:
            return self.__d.__getattribute__(attr)
        except AttributeError:
            raise AttributeError("'AutoIncDict' object has no attribute '%s'" % attr)
Example #3
0
 def __getattr__(self, name):
     try:
         return self[name]
     except:
         pass
     return OrderedDict.__getattribute__(self, name)
Example #4
0
 def __getattr__(self, key):
     if key.startswith("_"):
         return OrderedDict.__getattribute__(self, key)
     return self.__getitem__(key)