1 回答

TA贡献1810条经验 获得超5个赞
错误是因为这段代码:
try:
line2 = 1
except NameError:
break
else:
for char in line2:
keyboard.press(char)
keyboard.release(char)
time.sleep(0.1)
之后line2 = 1,line2不再包含用户输入的行,而是包含整数1。for char in line2将不再有效,因为您无法遍历整数。
我认为您正在尝试使用该try/except块来判断用户是否为line2. 但是赋值永远不会报告 a NameError,只有在尝试读取尚未赋值的变量时才会出现该错误。此外,读取输入的代码始终分配给line2,因此您不会收到错误消息。如果您为前几行输入,则可能未设置的变量是line3and 。line4none
每当您发现自己创建的变量具有这样的顺序名称时,您可能应该使用列表而不是单独的变量。以下是读取所有输入行的方法:
lines = []
while True:
line = input("Please enter your next line, type 'none' if you don't have one")
if line == "none":
break
lines.append(line)
当你想输入它们时:
random.seed()
while time.time() < future and runs < hours*60:
for line in lines:
for char in line:
keyboard.press(char)
keyboard.release(char)
time.sleep(0.1)
keyboard.press(Key.shift)
keyboard.press(Key.enter)
keyboard.release(Key.shift)
keyboard.release(Key.enter)
runs += 1
print("Random Seconds Added:")
print(int(random1))
print("Time to next entry:")
for y in range(int(retry) + int(random1)):
print(int(retry) + int(random1 - y))
time.sleep(1)
另一个问题是您timeout在循环期间从未更新,它始终是它开始的时间。
添加回答
举报