您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

使用记事本作为python中的帮助文件打开文本文件?

使用记事本作为python中的帮助文件打开文本文件?

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

尽管它的名称是,它将在记事本,gedit等中打开。从未尝试过,但据说可以奏效。

替代方法是使用

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

或作为子流程:

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

但是在这两种情况下,您都需要先找到给定操作系统的本机文本编辑器。

python 2022/1/1 18:33:38 有519人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶