summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSiddharth Ravikumar <sravik@bgsu.edu>2015-10-16 23:20:06 -0400
committerSiddharth Ravikumar <sravik@bgsu.edu>2015-10-16 23:20:06 -0400
commitdf9497d7c18a6dc7e7a284b7087765ca464e8a6b (patch)
tree191c65eaed398136beab8fe8a4ff0c9c47a6ce6e
parent49ea6f4a2fc4588b298329dd75c76cbc56b59562 (diff)
refactored read_file function combox.file module.
Thanks https://stackoverflow.com/questions/8009882/how-to-read-large-file-line-by-line-in-python
-rw-r--r--combox/file.py11
1 files changed, 4 insertions, 7 deletions
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