From 6b9453afa1000d1889116658cbcb896f1c297df7 Mon Sep 17 00:00:00 2001 From: "Vgr E. Barry" Date: Sat, 8 Oct 2016 08:47:23 -0400 Subject: [PATCH] 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. --- src/wolfgame.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/wolfgame.py b/src/wolfgame.py index 748155e..1b989fa 100644 --- a/src/wolfgame.py +++ b/src/wolfgame.py @@ -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", " ")