Open PDF with default program in Windows 7
I have a program in which the help documentation is in a .pdf in the same folder as the .py module. I need the program to open the .pdf with the system's default PDF reader.
I am using this code in my program:
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")
However, when this is run in Windows 7, I get the following error:
Traceback (most recent call last): File "C:\Users\user\MousePaw Games\MousePaw Labs\Slannan\Slannan.py", line 1286, in help_ev开发者_如何转开发ent os.filestart("SlannanHelp.pdf") AttributeError: 'module' object has no attribute 'filestart'
My guess is that os.filestart works in NT systems, but not in Windows 7. Is there a command that works for both, or one that just works for Windows 7? If the latter, how do I check to see if the user is running an NT or 7 version of Windows?
Thanks in advance!
The problem is os.filestart
does not exist at all.
You problably want os.startfile
You should also take a look at:
Open document with default application in Python
and How to open a file with the standard application? which recommend system('open', filepath)
on mac and system('xdg-open', filepath)
on linux
精彩评论