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:
try:
out = subprocess.check_output(("fortune", "-s"))
except OSError as e:
if e.errno != 2:
# No such file or directory (fortune is not installed)
raise
except FileNotFoundError:
pass
else:
out = out.decode("utf-8", "replace")
out = out.replace("\n", " ")