调用$ EDITOR很容易。我已经编写了这种代码来调用编辑器:
import sys, tempfile, osfrom subprocess import callEDITOR = os.environ.get('EDITOR','vim') #that easy!initial_message = "" # if you want to set up the file somehowwith tempfile.NamedTemporaryFile(suffix=".tmp") as tf: tf.write(initial_message) tf.flush() call([EDITOR, tf.name]) # do the parsing with `tf` using regular File operations. # for instance: tf.seek(0) edited_message = tf.read()这里的好处是,库可以处理创建和删除临时文件。



