UniCoreFW

property_of()

Return a function that retrieves a property value from a given object.

Implementation

Args: obj: The object to get properties from Returns: A function that gets properties from the object

Example

obj = {'a': 1, 'b': 2} property_of(obj)('a')

Expected output: 1

Source Code

def property_of(obj: Any) -> Callable: return ( lambda prop_name: obj.get(prop_name) if isinstance(obj, dict) else getattr(obj, prop_name, None) )