Open a text file using notepad as a help file in python?

import webbrowser
webbrowser.open("file.txt")

Despite it’s name it will open in Notepad, gedit and so on. Never tried it but it’s said it works.

An alternative is to use

osCommandString = "notepad.exe file.txt"
os.system(osCommandString)

or as subprocess:

import subprocess as sp
programName = "notepad.exe"
fileName = "file.txt"
sp.Popen([programName, fileName])

but both these latter cases you will need to find the native text editor for the given operating system first.

Leave a Comment