How would I go about making a file open. Not the way you might think.
kyosohma at gmail.com
kyosohma at gmail.com
Thu Aug 23 16:53:37 EDT 2007
On Aug 23, 3:45 pm, Larry Bates <larry.ba... at websafe.com> wrote:
> Hendrik van Rooyen wrote:
> > Lamonte Harris wrote:
>
> >> Basically you can open a file by double clicking, and by default it would open
> > w/ what every program you have it set >to. Most text files would open in
> > notepad. How can I make a txt open so that notepad opens w/ the content in it
> > by >using just python.
>
> > I asked this question just yesterday - and Tim Golden answered:
>
> > os.startfile()
>
> > - Hendrik
>
> Actually os.startfile('filename.txt') will open the file with whatever
> application is associated with .txt files on that machine. That could be
> different from notepad if the user has chosen to override the defaults.
>
> os.system('notepad.exe c:\\junk.txt')
>
> will force notepad.exe to load and it will load the file specified.
>
> All depends on what you want to do.
>
> -Larry
That's true, but technically you should use the subprocess.Popen
module with Shell=True rather than the os.system method. At least, in
the newer Python versions, that seems to be the recommendation.
Mike
More information about the Python-list
mailing list