From 31c36756c7e1d398ce8425f1c50cd24c01b1ab14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A4rsson?= Date: Mon, 16 Oct 2017 10:03:47 +0200 Subject: [PATCH] Return None when edited file does not exist If a user edits a new, non-existent file and decides to not save it, edit() will return None instead of raising an exception. --- editor.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/editor.py b/editor.py index 54ee697..9bf5046 100755 --- a/editor.py +++ b/editor.py @@ -97,8 +97,10 @@ def edit(filename=None, contents=None, use_tty=None): proc = subprocess.Popen(args, close_fds=True, stdout=stdout) proc.communicate() - with open(filename, mode='rb') as f: - return f.read() + if os.path.isfile(filename): + with open(filename, mode='rb') as f: + return f.read() + return None def _get_editor(ns):