如何使用标准应用程序打开文件? [英] How to open a file with the standard application?

查看:88
本文介绍了如何使用标准应用程序打开文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序将PDF打印到一个临时文件.如何使用Python中的默认应用程序打开该文件?

My application prints a PDF to a temporary file. How can I open that file with the default application in Python?

我需要一个解决方案

  • Windows
  • Linux(如果没有其他通用的,则使用带有Xfce的Ubuntu.)

推荐答案

操作系统.起始文件目前仅适用于Windows,但 xdg-open 将在运行X的任何UNIX客户端上可用.

os.startfile is only available for windows for now, but xdg-open will be available on any unix client running X.

if sys.platform == 'linux2':
    subprocess.call(["xdg-open", file])
else:
    os.startfile(file)

这篇关于如何使用标准应用程序打开文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆