In python3, how do i create objects with an instance name and multiple arguments from a list? I have an example here. I need a way to initialize in a for loop
with variable names that allow me to access the instance later.
class fruit():
def __init__(self, color, weight):
self.color = color
self.weight = weight
def scale(self):
print(f"{self.weight} kg")
# i can do
strawberry = fruit("red", 10)
strawberry.scale()
# output "10 kg"
# but i cant do
fruitlist = [
["cherry", "red", 5],
["banana", "yellow", 10],
["blueberry", "blue", 15],
]
for i in range(len(fruitlist)):
fruitname = fruitlist[i][0]
fruitname = fruit(fruitlist[i][1], fruitlist[i][2])
cherry.scale()
# output "undefined name cherry"