def read_settings(path):
    """
    Read settings from an external file.

    The external file must be simply formatted like:
        # These are settings.
        a = 0
        b = "one"
        c = {"two": 2, "three": True, "four": None}
        ""\"
        A long comment.
        ""\"
        d = 5
    A dictionary equivalent to the global namespace of the external file is
    returned.

    path is a string that specifies the path to the external settings file.
    """
    import ast
    literal_eval = ast.literal_eval
    settings_dict = {}
    with open(path) as f:
        open_tri_quote = False
        for n, line in enumerate(f):
            if open_tri_quote:
                if '"""' in line:
                    open_tri_quote = False
                    continue
                continue
            bare_line = line.strip()
            if bare_line.startswith('#') or not bare_line:
                continue
            if bare_line.startswith('"""'):
                open_tri_quote = True
                continue
            var_name, _, val = bare_line.partition('=')
            try:
                settings_dict[var_name.rstrip()] = literal_eval(val.lstrip())
            except:
                raise TypeError(
                    'settings file is not correctly formatted on line {}: {}'
                    .format(n, path))
    return settings_dict
