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

后端 未结 6 1951
攒了一身酷
攒了一身酷 2020-11-29 08:28

I would like to give users of my simple program the opportunity to open a help file to instruct them on how to fully utilize my program. Ideally i would like to have a littl

6条回答
  •  难免孤独
    2020-11-29 08:44

    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.

提交回复
热议问题