我正在使用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
答案 0 :(得分:0)
不是以字符开头的行是问题,for line in x
和x.readline
语句都是从文件中读取一行,所以你可能会打印出替代线。删除readline!
with open(path) as program_file:
for line in program_file:
print(line)