info_outline

Solutions will be available when this assignment is resolved, or after a few failing attempts.

Count Lines in File

Write a function that receives a path to a text file as parameter, and returns the amount of lines that text file has.

count_lines('test-file.txt')  # 10

Test Cases

test count lines - Run Test

import tempfile

def test_count_lines():
    fp = tempfile.NamedTemporaryFile(mode="w")
    fp.write('this is line 1\n')
    fp.write('this is line 2\n')
    fp.write('this is line 3\n')
    fp.flush()

    assert count_lines(fp.name) == 3

    fp.close()
def count_lines(filepath): pass