Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completes Task/03 #37

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
24 changes: 21 additions & 3 deletions task-03/get_top_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,34 @@
https://github.com/astropgh/learning-by-doing/tree/master/task-03
"""

def extract_data_lines(filename, start_text, end_text):
def extract_data_lines(
filename,
start_text,
end_text,
include_start=False,
include_end=False,
):
"""
open `filename`, and yield the lines between
the line that contains `start_text` and the line that contains `end_text`
"""
# fill in code as needed
with open(filename) as fh:
in_table = False
for line in fh:
# fill in code as needed
# use `yield line` to return desired lines but keep the function going

if start_text in line:
in_table = True
if include_start:
yield line

elif end_text in line:
if include_end:
yield line
break

bretthandrews marked this conversation as resolved.
Show resolved Hide resolved
if in_table:
yield line


if __name__ == '__main__':
Expand Down