【发布时间】:2015-10-15 16:16:31
【问题描述】:
我正在尝试让我的 python 代码自动更新。问题是代码每次运行时都会拉出四个 html 文件,因此浏览器中有四个新选项卡。
我尝试使用类似问题的答案自动更新:What is the best way to repeatedly execute a function every x seconds in Python?
import time
starttime = time.time()
while True:
# My code here
output_file("first.html", title="First HTML Page")
# More code
output_file("second.html", title="Second HTML Page")
# Even more code
time.sleep(60.0 - ((time.time() - starttime) % 60.0))
这种方法的问题是每分钟它会拉出四个标签——这意味着四分钟后我已经有 16 个标签了!
有人知道如何使用相同的标签自动更新吗?我什至会删除原始标签并替换它们,即使我认为这不太优雅。
编辑:我正在运行 Windows,目前使用 IE,但我也愿意迁移到 Firefox 或 Chrome。
【问题讨论】:
-
什么样的标签?网络浏览器标签?我们需要看到
output_file函数 -
@cdonts IE 中的 Web 浏览器选项卡。我不确定你所说的 output_file 函数是什么意思,为什么这很重要?
-
IE有python插件吗?
-
@jenryb 重要的是,看看你的代码是如何工作的。
-
@Mark 我不知道是不是这样。该代码也适用于 Firefox。基本上它选择默认浏览器并使用来自 Bokeh 的 output_file 命令打开四个选项卡。
标签: python time tabs refresh auto-update