def serialize_fields(obj, fields):
    """
    Put the value of each attribute name in `fields` into a dict and return the dict.

    If a field is callable, it will be called with no arguments.

    e.g.

    class example:
        a = 1
        b = 2

        def c(self):
            return 3

    bag = serialize_fields(example(), ("a", "b", "c"))

    bag == {"a": 1, "b": 2, "c": 3}

    """
    bag = {}
    for name in fields:
        field = getattr(obj, name)
        bag[name] = field() if callable(field) else field
    return bag
