如何打印file.readline()行号?

2024-05-17 19:19:34 发布

您现在位置:Python中文网/ 问答频道 /正文

f = open("saves\\" + plrname + "_inv.txt", "r")
lines = f.readlines()
for x in range(500):
    if (x in lines) == "True\n":
        print(x)

.txt文件中有500行包含“True”或“False” 我想让程序读取它们,并根据它们的行号打印出哪些是正确的。 我已经试过“为x排好队”。我希望你能帮助我,谢谢

txt文件的外观示例:

True
True
True
False
False
True
False
False

Tags: 文件intxtfalsetrueforifrange