def nndb_recs(filename, field_names=None):
    """Iterator that yields a dictionary of (field-name,value) pairs.
    Note that the order of field_names is important!
    """
    if not field_names:
        raise ValueError("No fields specified for nndb recs")

    # Filter for a single field in the file
    def filt(f):
        if len(f) > 1 and f[0] == '~' and f[-1] == '~':
            f = f[1:-1]
        return f

    # Note the encoding - the documentation says the files are in
    # "ASCII (ISO/IEC 8859-1)" which might make you think you could assume
    # an encoding of ASCII or UTF-8, but they actually do use 8859-1 (latin_1)
    # characters that are not valid ASCII or UTF-8.
    with open(filename, "r", encoding="latin_1") as datafile:
        for line in datafile:
            line = line.strip()
            if len(line) < 1:
                continue
            yield dict([
                (name, filt(fld))
                for name, fld in zip(field_names, line.split('^'))
            ])