繁体   English   中英

Python:如何在记事本中打开json和html文件?

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

我试图在记事本中打开json和html文件。 我有以下代码:

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")

现在的问题是,命令提示符窗口闪烁约一秒钟,然后消失。 我需要将文件的内容显示在记事本中。

在Windows上使用python 3.3

提前致谢

您错过了system调用中的空格。 建议的修复:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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