Add a function to solutions/library.py that reads video URLs from a CSV file.
The CSV file is located at:
data/video_urls.csv
It contains 5 starter video URLs with titles.
Columns:
| title | url |
|---|---|
| Me at the zoo | https://www.youtube.com/watch?v=jNQXAC9IVRw |
| 10 sec 2D Test animation | https://www.youtube.com/watch?v=BB49x_uMlGA |
| [TEST] 10 Second Countdown | https://www.youtube.com/watch?v=Hm5ieMoxc4c |
| My Snowboarding Skillz | https://www.youtube.com/watch?v=LeAltgu_pbM |
| 10 Second Timer | https://www.youtube.com/watch?v=tCDvOQI3pco |
- In
solutions/library.py, create a function that reads the CSV file. - Use Python's built-in
csvmodule. - Return the URLs from the
urlcolumn. - Import the CSV-reading function into
solutions/main.py. - Print the list of URLs to check that it works.
Suggested function name read_video_urls(csv_path).
import csv
with open("data/video_urls.csv", newline="") as file:
reader = csv.DictReader(file)
for row in reader:
print(row["title"], row["url"])The CSV reader should live in solutions/library.py, not directly in solutions/main.py.
Your solutions/main.py should import the CSV-reading function from solutions/library.py. Print the list of URLs to check that it works.
Run:
python solutions/main.pyConfirm that:
- The app reads from
data/video_urls.csv. - The app prints a Python list of video URLs.
- The CSV-reading code lives in
solutions/library.py.