【发布时间】:2022-01-25 21:09:16
【问题描述】:
我可能会问一个简单的问题。我有一个每分钟运行的 python 程序。但是我希望代码块仅在条件更改后才运行?我的代码如下所示:
# def shortIndicator():
a = int(indicate_5min.value5)
b = int(indicate_10min.value10)
c = int(indicate_15min.value15)
if a + b + c == 3:
print("Trade posible!")
else:
print("Trade NOT posible!")
# This lets the processor work more than it should.
"""run_once = 0 # This lets the processor work more than it should.
while 1:
if run_once == 0:
shortIndicator()
run_once = 1"""
我在没有使用函数的情况下运行它。但是我每分钟都会得到一个输出。我尝试将它作为一个函数运行,当我启用它运行的注释代码时,处理使用量也更多。如果有更聪明的方法吗?
【问题讨论】:
-
不太清楚你的意思。如果您的意思是仅在结果更改时打印,请添加另一个变量来记住先前的结果并在条件中检查它。
-
是的,我正在尝试在结果更改时打印。否则我每 60 秒得到一个结果。像这样:交易不可能!交易不可能!交易不可能!交易可行!交易可行!交易可行!可以交易!
标签: python while-loop