Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
Replace read_stripped_lines with generator
Browse files Browse the repository at this point in the history
  • Loading branch information
forslund committed Mar 11, 2020
1 parent c075d65 commit c348115
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion mycroft/util/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ def read_stripped_lines(filename):
(list) list of lines stripped from leading and ending white chars.
"""
with open(filename, 'r') as f:
return [line.strip() for line in f]
for line in f:
line = line.strip()
if line:
yield line


def read_dict(filename, div='='):
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/util/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_read_stripped_lines(self):
expected = ['Once upon a time', 'there was a great Dragon',
'It was red and cute', 'The end']
unstripped_path = join(TestReadFiles.base, 'unstripped_lines.txt')
self.assertEqual(read_stripped_lines(unstripped_path), expected)
self.assertEqual(list(read_stripped_lines(unstripped_path)), expected)

def test_read_dict(self):
expected = {'fraggle': 'gobo', 'muppet': 'miss piggy'}
Expand Down

0 comments on commit c348115

Please sign in to comment.