如何在python 3中读取以算术字符开头的行

时间:2017-06-03 08:26:07

标签: python-3.x

我正在使用readline来读取文件,但是它的一些行以算术字符开头,readline跳过这一行, 有什么建议吗?

with open(path) as program_file:
for line in program_file:
    line = program_file.readline()
    print(line)

有些行是这样的:

2 4 5
+ 3 #skip this line
_ 5 9

1 个答案:

答案 0 :(得分:0)

不是以字符开头的行是问题,for line in xx.readline语句都是从文件中读取一行,所以你可能会打印出替代线。删除readline!

with open(path) as program_file:
    for line in program_file:
        print(line)