file_edit.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:roamer 作者: abaldwin88 项目源码 文件源码
def file_editor(content):
    with tempfile.NamedTemporaryFile(suffix=".roamer") as temp:
        if sys.version_info[0] == 3:
            content = content.encode('utf-8')
        temp.write(content)
        temp.flush()
        if EXTRA_EDITOR_COMMAND:
            exit_code = call([EDITOR, EXTRA_EDITOR_COMMAND, temp.name])
        else:
            exit_code = call(EDITOR.split() + [temp.name])
        if exit_code != 0:
            sys.exit()
        temp.seek(0)
        output = temp.read()
        if sys.version_info[0] == 3:
            output = output.decode('UTF-8')
        return output
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号