mak_paint wrote: ↑Thu Feb 03, 2022 10:01 pm
OlivierLenoir wrote: ↑Sat Jan 29, 2022 9:17 am
If the list of color is very long, I recommend using a
json file outside of your code.
hello, I'm a bit confused about what you mean when you tell me to use json outside the code
Create a
json file name it
cars.json and write the following
json structure in it. Documentation is
here
Code: Select all
{"ford": {"ranger_2011_2016": [0, 1, 0, 1, 0, 1], "explorer_2008_2012": [0, 1, 0, 1, 0, 1], "fiesta_2006": [0, 1, 0, 1, 0, 1], "fiesta_2006_2010": [0, 1, 0, 1, 0, 1]}, "chevrolet": {"aveo_2008_2012": [0, 1, 0, 1, 0, 1], "corsa_2005": [0, 1, 0, 1, 0, 1], "corsa_2006_2010": [0, 1, 0, 1, 0, 1], "corsa_2011_2016": [0, 1, 0, 1, 0, 1]}}
You can access
json data like that.
Code: Select all
from json import load
DATA_JSON = 'cars.json'
with open(DATA_JSON) as _json:
cars = load(_json)