games=[]
file=open("egames.txt",'r')
for game in file:
games.append(game)
file.close()
print("All games made by Rockstar Games")
for game in games:
currentline=game.split(",")
publisher=currentline[5]
if publisher=="Rockstar Games":
print(currentline[0],currentline[1])
Rockstar Games我没有任何错误,我什么也没打印]。The actual Text file
答案 0 :(得分:3)
从文件迭代器读取的行以换行符结尾。您应将其作为规范化的一部分:
for game in file:
games.append(game.rstrip())
答案 1 :(得分:1)
我猜测问题是尾随换行符,您看不到它们。尝试剥离任何空白:
publisher = currentline[5].strip()