def attrdict(obj):
    """Create a dictionary of all attributes in an object. This will work for
    classes with __slots__ or __dict__.    The returned object may or may not be the
    object and so should *not be modified*"""
    try:
        return vars(obj)
    except TypeError:
        return {a: getattr(obj, a) for a in dir(obj)}