I'm working on a project that has this structure:
- src/
- data/ with csv and txt files
- mod/ with python classes
- main.py
classes in mod/ use read csv to get data in form of
class Currency:
def __init__(self, country_name: str):
self.country = country_name
self.code = self.get_code()
def get_code(self) -> str:
with open("../data/iso-4217.csv") as file:
country_list = list(csv.reader(file))
for row in country_list[1:]:
if row[0] == self.country:
code = row[1]
return code
And it works just fine. But whenever I import the class itself to main.py, I get
FileNotFoundError: [Errno 2] No such file or directory: '../data/iso-4217.csv'
Is there a way to make correct import using relative pathing?
Using absolute pathing seems to fix the issue, but i'd rather use relative