def hasattr_nested(obj, attr):
    """
    Check whether an object contains a specified (possibly nested) attribute
    
    ie:
    
    hasattr_nested(obj, 'x.y.z') will check if obj.x.y.z exists
    """
    
    parts = attr.split('.')
    
    for part in parts:
        
        if hasattr(obj, part):
            obj = getattr(obj, part)
        else:
            return False
    else:
        return True