pythonでファイルを1行ずつ読み込む方法

行頭に # 付きはコメント行、空白行は読み飛ばす

def read_txt(filename):
    lines = []
    for line in open(filename, 'r'):
        if len(line) == 1:
            continue
        if line[0] == "#":
            continue
        lines.append(line)
    return lines
def read_data12(filename):
    items = {}
    for line in open(filename, 'r'):
        if len(line) == 1:
            continue
        if line[0] == "#":
            continue
        item_list = line.split()
        items["data1"] = float(item_list[0])
        items["data2"] = float(item_list[1])
    return items
data1 = []
data2 = []
for line in open(filename, 'r'):
    if len(line) == 1:
        continue
    if line[0] == "#":
        continue
    item_list = line.split()
    data1.append(float(item_list[0]))
    data2.append(float(item_list[1]))

print(data1)
print(data2)