python - 在 Windows 7 中使用默认程序打开 PDF

标签 python file sys

我有一个程序,其中的帮助文档位于与 .py 模块相同的文件夹中的 .pdf 文件中。我需要使用系统默认的 PDF 阅读器打开 .pdf 的程序。

我在我的程序中使用这段代码:

if sys.platform.startswith('darwin'):
    os.system("SlannanHelp.pdf")
elif sys.platform.startswith('linux'):
    os.system("SlannanHelp.pdf")
elif sys.platform.startswith('win32'):
    os.filestart("SlannanHelp.pdf")

但是,当它在 Windows 7 中运行时,出现以下错误:

Traceback (most recent call last): File "C:\Users\user\MousePaw Games\MousePaw Labs\Slannan\Slannan.py", line 1286, in help_event os.filestart("SlannanHelp.pdf") AttributeError: 'module' object has no attribute 'filestart'

我的猜测是 os.filestart 在 NT 系统中有效,但在 Windows 7 中无效。是否有适用于两者的命令,或仅适用于 Windows 7 的命令?如果是后者,我如何检查用户运行的是 NT 还是 7 版本的 Windows?

提前致谢!

最佳答案

问题是 os.filestart 根本不存在。

您可能需要 os.startfile

您还应该看看: Open document with default application in PythonHow to open a file with the standard application?在 mac 上推荐 system('open', filepath) ,在 linux 上推荐 system('xdg-open', filepath)

关于python - 在 Windows 7 中使用默认程序打开 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7343388/

相关文章:

python - 如何在存储控制台实时输出的同时运行 python 脚本?

python - Sys.path.insert 插入模块路径,但导入不起作用

c - 写入文件和映射内存有什么区别?

python - 调用 Client.Submit 时 Dask 出现 PicklingError

python - Python 的 eval() 有什么作用?

Python:三重双引号字符串格式

typescript - 如何在不使用 FileTransfer 的情况下从 Ionic 5 中的 url 下载文件

java - 使用 BufferedWriter 将相同数据写入多个文件

Python 不会读取 sys.argv

python - 扭曲随机序列的变换产生随机序列?