【发布时间】:2014-03-27 02:29:08
【问题描述】:
我有一个python文件html_gen.py,它在同一目录中写入了一个新的html文件index.html,并希望在写入完成后打开index.html。
所以我写了
import webbrowser
webbrowser.open("index.html");
但是执行 .py 文件后什么也没有发生。如果我改为输入代码
webbrowser.open("http://www.google.com")
Safari 将在执行代码时打开谷歌首页。
不知如何打开本地的index.html文件?
【问题讨论】:
-
如果调用内置的
open('index.html')会报错吗?它检查您是否可以打开文件进行阅读。 -
无法在 Python 2.7.6、Ubuntu 14.04、Firefox 47 上重现。
-
webbrowser.open('index.html', new=2, autoraise=True) 工作正常,分号是否打破它?