问题是你混合了两种读取文件的方法.
for a in apertura: # this reads in the first line of the file print(apertura.read()) # this reads the remainder of the file in one chunk
所以文件的第一行永远不会打印出来.
您可以像这样逐行遍历文件:
for a in apertura: print(a)
您还可以使用上下文管理器确保文件随后关闭
#!/usr/bin/python from sys import argv script, file = argv with open(file, 'r') as apertura: for a in apertura: print(a)
如果你真的想要使用它来读取文件.read()
,代码会稍微简单,但在文件很大的情况下会占用大量内存
#!/usr/bin/python from sys import argv script, file = argv with open(file, 'r') as apertura: print(apertura.read())