Project

General

Profile

« Previous | Next » 

Revision 1911

dicts.py: Added AttrsDictView

View differences:

dicts.py
24 24
            except KeyError: pass
25 25
        raise # reraise last KeyError
26 26

  
27

  
28
class AttrsDictView:
29
    '''A dict view of an object's attributes
30
    @pre If you want __iter__() to work, value must have a __dict__
31
    '''
32
    
33
    def __init__(self, value): self.value = value
34
    
35
    def __iter__(self): return iter(self.value.__dict__)
36
    
37
    def __getitem__(self, key): return getattr(self.value, key)
38

  
27 39
def make_hashable(value):
28 40
    if isinstance(value, list): value = tuple(value)
29 41
    elif isinstance(value, dict): value = util.NamedTuple(**value)

Also available in: Unified diff