If you are using SublimeText as the editor, you will need to pass in the -w
or --wait
argument to make sure that the Python program waits until you actually close SublimeText again.
Otherwise, you would just start to edit the file, and immediately try to read its contents which at that point are empty.
You could also verify that, by putting in a print
before reading the file.
E.g.:
editor = ['/path/to/sublime_text', '-w']
with tempfile.NamedTemporaryFile(delete=False) as f:
f.close()
if subprocess.call(editor + [f.name]) != 0:
raise IOError()
# read file…