3

Is there a (simple) way to launch the Windows default text editor from a Python script, like the webbrowser module?

NOTE: This is a repost of this question but I don't feel like the question is being answered. I need to open Window's default text-editor without it necessarily being a *.txt file being opened. May it be .xml, .html etc.

For example:

I know that:

notepadexec = "C:/Windows/System32/notepad.exe {}".format(myfile)
subprocess.Popen(notepadexec)

will open the file in notepad editor even if myfile is a html file, but I want Windows default editor to somehow be chosen.

And yes, the following:

os.system("{}".format(myfile))

will open the file in Windows default editor but only if myfile is a text file. Aaand it will also open the default browser if it's a html file.

Clarifying the question with an example: How do I open a html file for editing purposes with Windows default text-editor in a python script?

niCk cAMel
  • 869
  • 1
  • 10
  • 26
  • if you want to use the command line, then you have to make a function that parses the input_filename and then, depending on the extension, it will open it with the correct editor. Something like `if extension == '.txt': editor='notepad.exe'` Also, notepad is an editor, the browser is not! – alec_djinn May 05 '17 at 12:18
  • Maybe I'm not being clear... I'll read my question and perhaps edit it to be more clear – niCk cAMel May 05 '17 at 15:50
  • @alec_djinn I've edited to clarify the question. – niCk cAMel May 05 '17 at 20:07

0 Answers0