3

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_event 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!

Tyler Crompton
  • 12,284
  • 14
  • 65
  • 94
CodeMouse92
  • 6,840
  • 14
  • 73
  • 130

1 Answers1

7

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

Community
  • 1
  • 1
Mihai Stan
  • 1,052
  • 6
  • 7
  • I'll try that. I was using the xdg-open and open functions, but for some reason, they vanished in the C&P... – CodeMouse92 Sep 08 '11 at 15:32
  • It works! I can't find enough upvote buttons for your answer. Succinct, effective, and to the point. You solved my problem, AND pointed out another error in my file that I had missed. Thank you!! – CodeMouse92 Sep 08 '11 at 17:05