From: Max G Date: Sat, 11 Jul 2020 10:58:44 +0000 (+0300) Subject: Use 'with' to not leave a resource open X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=0a96dcad34f3aae9b11df7d53a25fc620551ac5c;p=stevenblack-hosts.git Use 'with' to not leave a resource open --- diff --git a/updateHostsFile.py b/updateHostsFile.py index 8eaff1717..a73da4f25 100644 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -1483,9 +1483,9 @@ def get_file_by_url(url): """ try: - f = urlopen(url) - soup = BeautifulSoup(f.read(), "lxml").get_text() - return "\n".join(list(map(domain_to_idna, soup.split("\n")))) + with urlopen(url) as f: + soup = BeautifulSoup(f.read(), "lxml").get_text() + return "\n".join(list(map(domain_to_idna, soup.split("\n")))) except Exception: print("Problem getting file: ", url)