Use more specific OS exceptions

Python 3.3 added some more specific exceptions for OS-related
operations, specifically to help mitigate this kind of hard-to-read
boilerplate. See
https://docs.python.org/3/whatsnew/3.3.html#pep-3151-reworking-the-os-and-io-exception-hierarchy
for reference.
This commit is contained in:
Vgr E. Barry 2016-10-08 08:47:23 -04:00
parent 36b5543d24
commit 6b9453afa1

View File

@ -4095,10 +4095,8 @@ def transition_day(cli, gameid=0):
elif random.random() < var.FORTUNE_CHANCE: elif random.random() < var.FORTUNE_CHANCE:
try: try:
out = subprocess.check_output(("fortune", "-s")) out = subprocess.check_output(("fortune", "-s"))
except OSError as e: except FileNotFoundError:
if e.errno != 2: pass
# No such file or directory (fortune is not installed)
raise
else: else:
out = out.decode("utf-8", "replace") out = out.decode("utf-8", "replace")
out = out.replace("\n", " ") out = out.replace("\n", " ")