我有一个程序,其中的帮助文档位于与 .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 Python
和 How 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/