[Tutor] os.startfile

Alan Gauld alan.gauld at btinternet.com
Mon Dec 20 01:22:28 CET 2010

"Lang Hurst" <lang at tharin.com> wrote

> I can't install anything at work (XP computer), hence the stand 
> alone file.  Then when I run it, everything works fine, except when 
> I get to the point where I want notepad to open the file.  I can 
> browse to the file and manually open it with notepad and it's fine. 
> It just won't open with notepad from the script.

You have missed the most critical bit of information.

Can you open the text file without going through Notepad?
ie If you double click on the text file in Windows explorer
does Notepad open? os.startfile() relies on the same file
associations that explorer uses. If Explorer can start
Notepad then your program should also be able to.

But from your description it sounds like you are starting
Notepad then opening the file?

Given you are only dealing with Notepad and a text
file you could also just start Notepad directly from your program.
In fact you could even check the OS and call whichever helper
editor was associated with that OS. If you put that in a config file
the user could then change the editor if they didn't like the OS 

Just some thoughts,

Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list