我有一个功能,我想每10秒运行一次。这有一个全局变量,它是一个名为marketId
的字符串。
在某些时候,这个字符串会改变。当发生这种情况时,我想运行一个新功能。
为此,我尝试了以下方法:
def test():
print("working")
def loop():
marketId_list = []
while True:
time.sleep(10)
full_function()
marketId_list.append(marketId)
for i in marketId_list:
if marketId_list[i] != marketId_list[i-1]:
test()
但是当我运行loop()
函数时,我收到错误:
TypeError: list indices must be integers or slices, not str
任何帮助解决这个问题都将受到赞赏,欢呼。沙
试试这个:
for i, item in enumerate(marketId_list):
if i>0 and marketId_list[i] != marketId_list[i-1]:
test()