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

Python 3.x 如何在python 3中读取以算术字符开头的行,python-3.x,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 问题不在于以字符开头的行,而在于for line in x和x.readline语句都从

我使用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

问题不在于以字符开头的行,而在于
for line in x
x.readline
语句都从文件中读取了一行,因此您可能会打印出备用行。删除读线

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