Is there a simple way to lauch the systems default editor from a Python command-line tool, like the webbrowser module?
+1
A:
If you need to open a file for editing, you could be interested in this question.
Joril
2009-09-18 06:41:45
(This caveat also applies to my answer) If viewer and editor are separate, this opens the viewer in 9/10 cases. Call it on a HTML file and the web browser will open it for *viewing*.
kaizer.se
2009-09-18 11:32:32
You're right, of course :) Maybe the OP will clarify which filetype she needs to handle..
Joril
2009-09-18 13:04:55
+2
A:
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 enviroment setting called EDITOR, so you need to use something like: os.system('%s %s' % (os.getenv('EDITOR'), filename))
A:
The modern Linux way to open a file is using xdg-open
; however it does not guarantee that a text editor will open the file. Using $EDITOR
is appropriate if your program is command-line oriented (and your users).
kaizer.se
2009-09-18 09:38:48