Browse Source

Fix quote.py to not crash when given an invalid filename

pull/21/head
Jake Zaia 4 years ago
parent
commit
b6187f48c0
1 changed files with 7 additions and 3 deletions
  1. +7
    -3
      src/quote.py

+ 7
- 3
src/quote.py View File

@ -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))]))

Loading…
Cancel
Save