This is a software design question. I have a folder like this:
JavaScript
x
12
12
1
api.py
2
calendar/
3
__init__.py
4
asia/
5
europe/
6
__init.py
7
germany.py
8
italy.py
9
america/
10
11
12
Each of the countries has its own calendar, like so:
JavaScript
1
14
14
1
## germany.py
2
from some_other_library import get_calendar
3
4
munich_params = { }
5
munich_calendar = get_calendar("DE",
6
start_time='2020-01-01',
7
end_time='2020-05-01',
8
params=munich_params)
9
berlin_params = { }
10
berlin_calendar = get_calendar("DE",
11
start_time='2020-01-01',
12
end_time='2020-05-01',
13
params=berlin_params)
14
JavaScript
1
20
20
1
## italy.py
2
from some_other_library import get_calendar
3
4
milan_params = { }
5
milan_calendar = get_calendar("IT",
6
start_time='2020-01-01',
7
end_time='2020-05-01',
8
params=milan_params)
9
rome_params = { }
10
rome_calendar = get_calendar("IT",
11
start_time='2020-01-01',
12
end_time='2020-05-01',
13
params=rome_params)
14
15
palermo_params = { }
16
palermo_calendar = get_calendar("IT",
17
start_time='2020-01-01',
18
end_time='2020-05-01',
19
params=palermo_params)
20
What I want is a wrapper to all of these countries’ calendars. In short, something like
JavaScript
1
11
11
1
## api.py
2
3
def get_calendar():
4
code code code
5
pass
6
7
#######################
8
9
> import api
10
> calendar = api.get_calendar("munich")
11
I don’t want to hard code this. I just want to load all the calendars from the calendar folder into some wrapper. Maybe an enum class instead of a function? Not sure.
If no answer, any thoughts or resources where I can look for this?
Advertisement
Answer
You are looking for the Factory Pattern