import codecs


def read_lines(infile, ignore_comments=True, strip=True, skip_empty=True):
    """Read lines from infile and return as a list, optionally stripping comments,
    whitespace, and/or skipping blank lines."""
    lines = []
    with codecs.open(infile, "r", "utf-8") as f:
        for line in f:
            if ignore_comments:
                ix = line.find("#")
                if ix >= 0:
                    line = line[:ix]
            if strip:
                line = line.strip()
            if not line and skip_empty:
                continue
            lines.append(line)
    return lines