comparison python/tmpbuffer.py @ 859:b8510769d001

py3 compat
author Jeff Hammel <k0scist@gmail.com>
date Wed, 11 Apr 2018 12:28:37 -0700
parents e07b99607d27
children
comparison
equal deleted inserted replaced
858:ebfcbbc8a627 859:b8510769d001
16 raise Exception("tmpbuffer: editor not supplied and EDITOR not defined") 16 raise Exception("tmpbuffer: editor not supplied and EDITOR not defined")
17 tmpfile = tempfile.mktemp(suffix='.txt') 17 tmpfile = tempfile.mktemp(suffix='.txt')
18 cmdline = editor.split() # XXX shlex would be more powerful 18 cmdline = editor.split() # XXX shlex would be more powerful
19 cmdline.append(tmpfile) 19 cmdline.append(tmpfile)
20 edit = subprocess.call(cmdline) 20 edit = subprocess.call(cmdline)
21 buffer = file(tmpfile).read().strip() 21 buffer = open(tmpfile).read().strip()
22 os.remove(tmpfile) 22 os.remove(tmpfile)
23 return buffer 23 return buffer
24 24
25 if __name__ == '__main__': 25 if __name__ == '__main__':
26 # purely for testing/illustration purposes 26 # purely for testing/illustration purposes
27 contents = tmpbuffer() 27 contents = tmpbuffer()
28 print contents 28 print (contents)
29 29