summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorLucas Hoffmann <l-m-h@web.de>2016-12-15 00:33:00 +0100
committerLucas Hoffmann <l-m-h@web.de>2016-12-15 00:33:00 +0100
commit7363c639b982b2dd35b12d28e33a91b9d8ae4f14 (patch)
treebcd91f88e372653491b7ec0c720a707321abbab3 /alot
parentc91c8df78ff64409f6a0e238b70add337353814c (diff)
Address comments by @dcbaker
Diffstat (limited to 'alot')
-rw-r--r--alot/ui.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/alot/ui.py b/alot/ui.py
index a57f8522..d9e0d466 100644
--- a/alot/ui.py
+++ b/alot/ui.py
@@ -707,12 +707,12 @@ class UI(object):
:type size: int
:returns: a list of history items (the lines of the file)
:rtype: list(str)
-
"""
if size == 0:
return []
if os.path.exists(path):
- lines = [line.rstrip('\n') for line in open(path).readlines()]
+ with open(path) as histfile:
+ lines = [line.rstrip('\n') for line in histfile]
if size > 0:
lines = lines[-size:]
return lines
@@ -732,7 +732,6 @@ class UI(object):
:type size: int
:type path: str
:returns: None
-
"""
if size == 0:
return
@@ -741,4 +740,8 @@ class UI(object):
directory = os.path.dirname(path)
if not os.path.exists(directory):
os.makedirs(directory)
- open(path, 'w').write('\n'.join(history))
+ # Write linewise to avoid building a last string in menory.
+ with open(path, 'w') as histfile:
+ for line in history:
+ histfile.write(line)
+ histfile.write('\n')