python - 如何正确使用 enumerate 和 .append 函数?
问题描述
我是编程新手,这是我第一次尝试自己做点什么。我正在尝试制作一个简单的程序来检测何时将某些内容写入 .txt 文件。现在我的“for”循环中的第一个“if”语句有效,所以我可以用它做点什么。但是当我想继续第二个时,即使满足 .txt 文件中的要求,也会出现问题并且它不会打印“success2”。我对 .append 和 enumerate 函数还不是很满意,所以我自己看不到问题所在。感谢任何可能提供帮助的人!
from win32 import win32gui
import win32ui
import time
def League_Running():
#Checks if the client is running and returns True or False
if win32ui.FindWindow(None, "League of Legends (TM) Client"):
return True
else:
print("not found")
return False
firstused = False
secondused = False
while League_Running():
content = []
linenumber = {4}
for i, note in enumerate(open(r'C:\Riot Games\League of Legends\MyNotes.txt', "r")): #Opens the .txt file
if i in linenumber:
if linenumber == {4} and linenumber!= None and not firstused:
content.append(note) #adds the line in the .txt file to the content list
if "test" in str(content): #checks for a specific line in the content list
print("success")
firstused = True #so it doesnt get printed out 100x every second, will add time.sleep() later
linenumber = {5}
content.remove(note) #not sure if this is necessary?
if linenumber == {5} and linenumber!= None and not secondused:
content.append(note) #pretty sure this is where it breaks
if "hello" in str(content):
print("success2")
secondused = True
linenumber = {6}
.txt 文件的内容:
#
2020-05-16_14-29-53_
#
测试
你好
解决方案
推荐阅读
- c# - 在空间之前替换价值?
- php - 无法运行从 php 到 linux 的命令
- amazon-web-services - Terraform aws - 将更改用于创建同名 s3 存储桶的模块删除 s3 存储桶并重新创建它
- css - 将 2 个块渲染为单个元素
- c - 即使在 select() 以可读的服务器套接字返回后,客户端上的 SSL_read() 也会阻塞
- c++ - 使用 OpenCV C++ RaspberryPi 的慢速 FPS
- vba - VBA:用户定义类型作为公共对象模块中的事件参数
- android - 如何防止 Android 模拟器断开代理 Wifi
- amazon-lightsail - Lightsail 自定义 DNS
- android - 如何从手机/手机传递一些信息来佩戴操作系统并将其显示在 android wear os 模拟器中?