简体   繁体   中英

Python: How to open json and html files in notepad?

Im trying to open json and html files in notepad. I have the following code:

def openFile():
    fileName = listbox_1.get(ACTIVE)
    if fileName.endswith("json") or fileName.endswith("htm"):
        os.system("notepad.exe" + fileName)
    elif fileName.endswith("jpeg"):
        os.startfile(fileName)
    else:
        messagebox.showerror(title="Error", message="File is not relevant, please choose one with a directory")

The problem is at the moment all that happens is that a command prompt window flashes up for about a second then disappears. I need for the content of the file to be displayed in notepad.

Using python 3.3 on windows

Thanks in advance

You've missed a space in system call. Proposed fix:

os.system('notepad.exe {}'.format(fileName))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM