30-Days-Of-Python
30-Days-Of-Python copied to clipboard
Day 10 Level 3 Exercise 3
Go to the data folder and use the countries_data.py file.
This is the level 3 exercise 3 for day 10. I am struggling with how exactly i import and use the list? dictionary? to be able to extract stuff so that i can actually do the exercises. Could someone be able to help with this? I managed to do it for country.py by doing the following and I tried the same for countries_data.py but it doesnt seem to work.
import sys
import os
# Determine the current and parent directory paths
current_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.abspath(os.path.join(current_dir, os.pardir))
# Add the parent directory to sys.path
sys.path.append(parent_dir)
from data.countries import countries```
I ran into this same issue!
I was able to tweak a Stack Overflow post + some code from the 'modules' day (day 12) to get the following to work:
import countries_data
countries_data.countries[1]
Note though that I also needed to add countries = to the start of the first line of countries-data.py and change the dash in the filename to an underscore (i.e., countries_data.py).
Hope this helps!