def read_csv(path, delim=','):
    """This function reads comma-separated values from a
    file. Parameter <path> is either a pathname or a file-like object
    that supports the |readline()| method.

    Empty lines and lines
    beginning with "#" are ignored.  Parameter <delim> specifies how
    a line is separated into values. If it does not contain the
    letter "%", then <delim> marks the end of a value.
    Otherwise, this function acts like scanf in C:

chart_data.read_csv('file', '%d,%s:%d')

    Paramter <delim> currently supports
    only three conversion format specifiers:
    "d"(int), "f"(double), and "s"(string)."""

    fd = _try_open_file(path, 'r',
                        'The first argument must be a pathname or an object that supports readline() method')

    data = []
    line = fd.readline()
    while line != "":
        if line[0] != '#' and not empty_line_p(line):
            data.append(parse_line(line, delim))
        line = fd.readline()

    _try_close_file(fd, path)
    return data