Use 'with' to not leave a resource open

This commit is contained in:
Max G 2020-07-11 13:58:44 +03:00
parent 0f727b8bed
commit 0a96dcad34

View File

@ -1483,9 +1483,9 @@ def get_file_by_url(url):
""" """
try: try:
f = urlopen(url) with urlopen(url) as f:
soup = BeautifulSoup(f.read(), "lxml").get_text() soup = BeautifulSoup(f.read(), "lxml").get_text()
return "\n".join(list(map(domain_to_idna, soup.split("\n")))) return "\n".join(list(map(domain_to_idna, soup.split("\n"))))
except Exception: except Exception:
print("Problem getting file: ", url) print("Problem getting file: ", url)