editor.py 文件源码

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

项目:Flask_Blog 作者: sugarguo 项目源码 文件源码
def edit(filename=None, contents=None):
    editor = get_editor()
    args = get_editor_args(os.path.basename(os.path.realpath(editor)))
    args = [editor] + args.split(' ')

    if filename is None:
        tmp = tempfile.NamedTemporaryFile()
        filename = tmp.name

    if contents is not None:
        with open(filename, mode='wb') as f:
            f.write(contents)

    args += [filename]

    proc = subprocess.Popen(args, close_fds=True)
    proc.communicate()

    with open(filename, mode='rb') as f:
        return f.read()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号