From 7e2b259db500f3eac61ce8c24fc19e0d587d7cb1 Mon Sep 17 00:00:00 2001 From: Alex Schroeder Date: Wed, 14 Aug 2019 12:58:28 +0200 Subject: [PATCH] Move reading notes into a separate function --- jan-pona-mute.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/jan-pona-mute.py b/jan-pona-mute.py index 332cf17..cac03ea 100755 --- a/jan-pona-mute.py +++ b/jan-pona-mute.py @@ -405,8 +405,7 @@ Use the 'edit' command to edit notes.""" notes = self.get_notes() if notes: try: - with open(self.get_note_path(notes[n-1]), mode = 'r', encoding = 'utf-8') as fp: - line = fp.read() + line = self.read_note(notes[n-1]) print("Using note #%d: %s" % (n, notes[n-1])) except IndexError: print("Use the 'list notes' command to list valid numbers.") @@ -528,6 +527,11 @@ Use the 'edit' command to edit notes.""" """Get the correct path for a note.""" return os.path.join(get_notes_dir(), filename) + def read_note(self, filename): + """Get text of a note.""" + with open(self.get_note_path(filename), mode = 'r', encoding = 'utf-8') as fp: + return fp.read() + # Main function def main(): -- 2.25.1