from pathlib import Path
import re


def namelist_exists(fn: Path, nml: str) -> bool:
    """
    Determines if a namelist exists in a file.
    Does not check for proper format / syntax.
    """

    pat = re.compile(r"^\s*&(" + nml + ")$")

    with fn.open("rt") as f:
        for line in f:
            if pat.match(line) is not None:
                return True

    return False