我已经成功地找到代码生成一个vim编辑和创建从python脚本一个临时文件。该代码是在这里,我在这里找到:call up an EDITOR (vim) from a python scriptvim编辑器在Python脚本临时文件
import sys, tempfile, os
from subprocess import call
EDITOR = os.environ.get('EDITOR','vim')
initial_message = ""
with tempfile.NamedTemporaryFile(suffix=".tmp") as tempfile:
tempfile.write(initial_message)
tempfile.flush()
call([EDITOR, tempfile.name])
我遇到的问题是,我无法访问临时文件的内容后,我退出编辑器。
tempfile
<closed file '<fdopen>', mode 'w+b' at 0x87c47b0>
tempfile.readline()
我得到
ValueError: I/O operation on closed file
我所做的:
myfile = open(tempfile.name)
IOError: [Errno 2] No such file or directory: '/tmp/tmp7VKzfl.tmp'
我将如何访问该文件在Python脚本一旦被编辑与编辑器?
谢谢
非常感谢您 – Neeran 2012-04-11 10:45:12