Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lauch default editor (like 'webbrowser' module)

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

like image 202
pkit Avatar asked Sep 18 '09 06:09

pkit


1 Answers

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

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

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'), filename))

like image 168
user175390 Avatar answered Sep 28 '22 07:09

user175390