diff options
author | Ville Skyttä <ville.skytta@iki.fi> | 2016-07-26 19:57:23 +0300 |
---|---|---|
committer | Ville Skyttä <ville.skytta@iki.fi> | 2016-07-26 19:57:23 +0300 |
commit | 22a03ad39a926b09ba6b8dc2a33988b80cae77a6 (patch) | |
tree | dfb96b9733f9d76c2436346f5ecbbd72957c1387 /bs4 | |
parent | c0c4eb5d89777c922e8cfd31b2ac8f86972e1f3c (diff) |
Open/close files with "with"
Diffstat (limited to 'bs4')
-rw-r--r-- | bs4/diagnose.py | 3 |
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." |