def get_dict_for_attrs ( obj , attrs ) : data = { } for attr in attrs : data [ attr ] = getattr ( obj , attr ) return data
how to dynamically build a dictionary in python
Returns dictionary for each attribute from given obj .
def get_dict_for_attrs(obj, attrs):
    """
    Returns dictionary for each attribute from given ``obj``.
    """
    data = {}
    for attr in attrs:
        data[attr] = getattr(obj, attr)
    return data