本文介绍了Lauch默认编辑器(如“ webbrowser”模块)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以从Python命令行工具中释放系统默认编辑器,例如模块?

Is there a simple way to lauch the systems default editor from a Python command-line tool, like the webbrowser module?

推荐答案

在Windows下,您可以简单地执行文件,并执行默认操作:

Under windows you can simply "execute" the file and the default action will be taken:

os.system('c:/tmp/sample.txt')

在此示例中,将生成默认编辑器。在UNIX下,有一个名为 EDITOR 的环境变量,因此您需要使用以下命令:

For this example a default editor will spawn. Under UNIX there is an environment variable called EDITOR, so you need to use something like:

os.system('%s%s'%(os.getenv('EDITOR'),文件名))

这篇关于Lauch默认编辑器(如“ webbrowser”模块)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 23:52
查看更多