From df9497d7c18a6dc7e7a284b7087765ca464e8a6b Mon Sep 17 00:00:00 2001 From: Siddharth Ravikumar Date: Fri, 16 Oct 2015 23:20:06 -0400 Subject: refactored read_file function combox.file module. Thanks https://stackoverflow.com/questions/8009882/how-to-read-large-file-line-by-line-in-python --- combox/file.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'combox') diff --git a/combox/file.py b/combox/file.py index b6ee97e..62ad16f 100644 --- a/combox/file.py +++ b/combox/file.py @@ -344,14 +344,11 @@ def read_file(filename): filename: Absolute pathname of the file. """ file_ = None - try: - file_ = open(filename, 'rb') - except IOError: - print "ERROR: opening %s" % (filename) - exit(1) + content = '' - content = file_.read() - file_.close() + with open(filename, 'rb') as f: + for line in f: + content = content + line return content -- cgit v1.2.3