From: Justin Findlay Date: Thu, 15 Sep 2016 18:57:31 +0000 (-0600) Subject: open file with a context manager X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=29a265681c2c429d5ffbd473fc64204779f12033;p=redacted-XKCD-password-generator.git open file with a context manager --- diff --git a/xkcdpass/xkcd_password.py b/xkcdpass/xkcd_password.py index 8bd8554..4903a57 100755 --- a/xkcdpass/xkcd_password.py +++ b/xkcdpass/xkcd_password.py @@ -114,14 +114,13 @@ def generate_wordlist(wordfile=None, # At this point wordfile is set wordfile = os.path.expanduser(wordfile) # just to be sure - wlf = open(wordfile) - for line in wlf: - thisword = line.strip() - if regexp.match(thisword) is not None: - words.append(thisword) - - wlf.close() + # read words from file into wordlist + with open(wordfile) as wlf: + for line in wlf: + thisword = line.strip() + if regexp.match(thisword) is not None: + words.append(thisword) return list(set(words)) # deduplicate, just in case