Welcome, guest | Sign In | My Account | Store | Cart
import os, tempfile

def edit(editor, content=''):
    f = tempfile.NamedTemporaryFile(mode='w+')
    if content:
        f.write(content)
        f.flush()
    command = editor + " " + f.name
    status = os.system(command)
    f.seek(0, 0)
    text = f.read()
    f.close()
    assert not os.path.exists(f.name)
    return (status, text)

Diff to Previous Revision

--- revision 1 2014-09-01 16:02:42
+++ revision 2 2014-09-01 18:26:51
@@ -1,4 +1,4 @@
-import tempfile
+import os, tempfile
 
 def edit(editor, content=''):
     f = tempfile.NamedTemporaryFile(mode='w+')

History