summaryrefslogtreecommitdiff
path: root/bs4/diagnose.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2016-07-26 21:27:28 -0400
committerLeonard Richardson <leonardr@segfault.org>2016-07-26 21:27:28 -0400
commitd45fdd36c11ccc91f5ea81e2caf4ae71c47a4f33 (patch)
treeb21305bdac96a3b329a5d7b07835163c9fb60e75 /bs4/diagnose.py
parentd728b532db6e6def64b447bd42cf9a8ff698f03a (diff)
parent22a03ad39a926b09ba6b8dc2a33988b80cae77a6 (diff)
Change the way open() is used. Code contributed by Ville Skyttä.
Diffstat (limited to 'bs4/diagnose.py')
-rw-r--r--bs4/diagnose.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/bs4/diagnose.py b/bs4/diagnose.py
index cda2f01..8768332 100644
--- a/bs4/diagnose.py
+++ b/bs4/diagnose.py
@@ -58,7 +58,8 @@ def diagnose(data):
data = data.read()
elif os.path.exists(data):
print '"%s" looks like a filename. Reading data from the file.' % data
- data = open(data).read()
+ with open(data) as fp:
+ data = fp.read()
elif data.startswith("http:") or data.startswith("https:"):
print '"%s" looks like a URL. Beautiful Soup is not an HTTP client.' % data
print "You need to use some other library to get the document behind the URL, and feed that document to Beautiful Soup."