Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions python2/koans/about_with_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ def count_lines(self, file_name):
try:
f = open(file_name)
try:
count = 0
for line in f.readlines():
count += 1
return count
return len(f.readlines())
finally:
f.close()
except IOError:
Expand Down Expand Up @@ -86,10 +83,7 @@ def __exit__(self, cls, value, tb):

def count_lines2(self, file_name):
with self.FileContextManager(file_name) as f:
count = 0
for line in f.readlines():
count += 1
return count
return len(f.readlines())

def test_counting_lines2(self):
self.assertEqual(__, self.count_lines2("example_file.txt"))
Expand All @@ -108,10 +102,7 @@ def test_finding_lines2(self):

def count_lines3(self, file_name):
with open(file_name) as f:
count = 0
for line in f.readlines():
count += 1
return count
return len(f.readlines())

def test_open_already_has_its_own_built_in_context_manager(self):
self.assertEqual(__, self.count_lines3("example_file.txt"))
15 changes: 3 additions & 12 deletions python3/koans/about_with_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ def count_lines(self, file_name):
try:
file = open(file_name)
try:
count = 0
for line in file.readlines():
count += 1
return count
return len(file.readlines())
finally:
file.close()
except IOError:
Expand Down Expand Up @@ -85,10 +82,7 @@ def __exit__(self, cls, value, tb):

def count_lines2(self, file_name):
with self.FileContextManager(file_name) as file:
count = 0
for line in file.readlines():
count += 1
return count
return len(file.readlines())

def test_counting_lines2(self):
self.assertEqual(__, self.count_lines2("example_file.txt"))
Expand All @@ -107,10 +101,7 @@ def test_finding_lines2(self):

def count_lines3(self, file_name):
with open(file_name) as file:
count = 0
for line in file.readlines():
count += 1
return count
return len(file.readlines())

def test_open_already_has_its_own_built_in_context_manager(self):
self.assertEqual(__, self.count_lines3("example_file.txt"))