Python系统自动调用默认程序实现打开文件操作方法是?,python打开文件,python 脚本生成


python 脚本生成 xls 文档后,希望自动调用系统的默认程序(比如 excel)打开该文档,应该如何操作?

Python 调用 Windows API:
http://my.oschina.net/fants/blog/89682

使用 Windows API 启动程序(传个参数就可以打开文件啦):
http://www.cnblogs.com/greatverve/archive/2010/12/24/window-api-exe.html

windows上可以使用os.startfile

os.startfile(file)

linux上可以使用xdg-open

subprocess.call(["xdg-open", file])

mac os上可以使用open

subprocess.call(["open", file])

用标准库里的webbrowser试试?

import webbrowserwebbrowser.open('file:///D:/path/to/table.xls')

编橙之家文章,

评论关闭