0

I was trying out stuff in order to try using classes and i came up with this code to remember orders from tables. But I got into a pickle trying to put too many variables inside a definition, and asked myself if it was even possible to have a variable as a suffix (so as a 'randomname'.variable)

class Nourriture:
    def __init__(self, entree, meal, dessert):
        self.entree = entree
        self.meal = meal
        self.dessert = dessert

John = Nourriture('poire à l\'anglaise','foie gras et entrecôte', 'creme brulée')
Marty = Nourriture('poire à la francaise','foie maigre et entrejambe', 'creme brulée')
Marie = Nourriture('rien','rien','rien')
Camille = Nourriture('rien','rien','crepe')

Tables = {
    'table1' : [John, Marty, Marie],
    'table2' : [Camille]
}

def repasorder (plat, tablenumber):
    return [Tables[tablenumber][i].plat for i in Tables[tablenumber]]

print(repasorder('meal','table1'))

(sorry some bits are in french)

I wanted to know how i could make this whole code work, I am aware there might be other problems in my code but I am pretty much stuck.

A bit of help is welcomed :D

  • Well, your immediate problem is that `for i in Tables[tablenumber]` *already gives your your `Nourriture` object*. So you meant something like `[nourriture.plat for nourriture in Tables[tablenumber]]` *however* `.plat` will not work that way, you'd have to use `getattr(nourriture, plat)` – juanpa.arrivillaga May 25 '21 at 18:17
  • @juan.arrivillaga Thanks! It worked like a charm ;) – Deedale May 25 '21 at 18:27

0 Answers0