degal/utils.py
changeset 128 f66bb9f6126a
parent 120 55cb7fc9c8fb
child 139 d3167c40e7b9
equal deleted inserted replaced
127:37d19805b7ca 128:f66bb9f6126a
    75         return tuple(self.func(obj))
    75         return tuple(self.func(obj))
    76 
    76 
    77 lazy_load = LazyProperty
    77 lazy_load = LazyProperty
    78 lazy_load_iter = LazyIteratorProperty
    78 lazy_load_iter = LazyIteratorProperty
    79 
    79 
       
    80 def unload (obj, *attrs) :
       
    81     """
       
    82         Un-load the named attributes from the given object.
       
    83     """
       
    84     
       
    85     for attr in attrs :
       
    86         if attr in obj.__dict__ :
       
    87             del obj.__dict__[attr]
       
    88 
    80 def first (iterable) :
    89 def first (iterable) :
    81     """
    90     """
    82         Returns the first item from the iterable that evaluates to True, otherwise None.
    91         Returns the first item from the iterable that evaluates to True, otherwise None.
    83 
    92 
    84         >>> first((0, 1))
    93         >>> first((0, 1))
    85         1
    94         1
    86         >>> first("abc")
    95         >>> first("abc")
    87         'a'
    96         'a'
    88         >>> first(('', list(), (), False))
    97         >>> first(('', list(), (), False))
    89         None
       
    90     """
    98     """
    91 
    99 
    92     for item in iterable :
   100     for item in iterable :
    93         if item :
   101         if item :
    94             return item
   102             return item