From b6187f48c01ea5fd76737d093e077c591e9647bb Mon Sep 17 00:00:00 2001 From: Jake Zaia Date: Fri, 18 Oct 2019 17:37:02 -0400 Subject: [PATCH] Fix quote.py to not crash when given an invalid filename --- src/quote.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/quote.py b/src/quote.py index 934fe63..f7bb8b3 100644 --- a/src/quote.py +++ b/src/quote.py @@ -37,9 +37,13 @@ def print_message(message, ascii_file = None): if ascii_file != None: filepath = '/'.join(INPUT_FILE.split('/')[:-1]) filepath += "/asciiArt/" + ascii_file - f = open(filepath, 'r') - print(f.read()) - f.close() + if (os.path.exists(filepath)): + f = open(filepath, 'r') + print(f.read()) + f.close() + else: + print(module.input_file_with_new_line( + ASCII_ART[random.randint(0,(len(ASCII_ART) -1))])) else: print(module.input_file_with_new_line( ASCII_ART[random.randint(0,(len(ASCII_ART) -1))]))