Hi everybody, I would appreciate your help on this one In this program I want to create 2 concepts each with 2 or 3 properties My first concept is magasin(shop in french) and my shop has 3 attributes: nom(name in french), items and ville (city in french) the second one is items and its 2 attributes are nom(name in french) and prix (price in french) I want to be able to show a modele with the name of my magasins (stores) and the city theyre located in, what are the names of the items i have in each magasin and their prices.
Here's my code: class Magasin: """ Le concept magasin pour la gestion d'inventaire des items de golf. """ def __init__(self, nom ="", items =[], ville="" ): self.nom = nom self.items = items self.vile = ville def set_nom(self, nom): self.nom = nom nom = property(None, set_nom) def set_items(self, items): self.items = items items = property(None, set_items) def set_ville(self, ville): self.ville = ville items = property(None, set_ville) def __str__(self): return self.nom class Item: """ Le concept item pour la gestion d'inventaire des items de golf. """ def __init__(self, nom ="", prix = 100): self.nom = nom self.prix = prix def set_nom(self, nom): self.nom = nom nom = property(None, set_nom) def set_prix(self, prix): self.prix = prix prix = property(None, set_prix) def __str__(self): return self.nom class Modele: """ La definition d'un modele avec les magasins. """ def __init__(self, nom_fichier, magasins =[]): self.nom_fichier = nom_fichier self.magasins = magasins def set_nom_fichier(self, nom_fichier): self.nom_fichier = nom_fichier nom_fichier = property(None, set_nom_fichier) def set_magasins(self, magasins): self.magasins = magasins magasins = property(None, set_magasins) def sauvegarder(self): modele_fichier = open(self.nom_fichier, 'w') for magasin in self.magasins: modele_fichier.write("===MAGASIN===" + "\n") modele_fichier.write("nom : " + magasin.nom + "\n") modele_fichier.write("items : " + "\n") for item in magasin.items: modele_fichier.write(" ---ITEM---" + "\n") modele_fichier.write(" nom : " + item.nom + "\n") modele_fichier.write(" prix : " + item.prix + "\n") modele_fichier.write(" ---FIN ITEM---" + "\n") modele_fichier.write("===FIN MAGASIN===" + "\n") modele_fichier.close() def charger(self): magasins = [] try: modele_fichier = open(self.nom_fichier, 'r') except IOError: print("Le fichier " + self.nom_fichier + " n'existe pas.") else: fin_fichier = False while not fin_fichier: ligne = modele_fichier.readline() if ligne == "": self.set_magasins(magasins) modele_fichier.close() fin_fichier = True break magasin = Magasin() items = [] fin_magasin = False while not fin_magasin: ligne = modele_fichier.readline().strip() if ligne.startswith("===FIN MAGASIN==="): magasin.set_items(items) magasins.append(magasin) fin_magasin = True elif ligne.startswith("nom"): nom = ligne.split(':')[1] magasin.set_nom(nom.strip()) elif ligne.startswith("---ITEM---"): item = Item() fin_item = False while not fin_item: ligne = modele_fichier.readline().strip() if ligne.startswith("nom"): nom = ligne.split(':')[1] item.set_nom(nom.strip()) elif ligne.startswith("prix"): prix = ligne.split(':')[1] item.set_prix(float()) elif ligne.startswith("---FIN ITEM---"): items.append(item) fin_item = True def vide(self): if self.magasins == []: return True else: return False def initialiser(self): magasin01 = Magasin ("Swing de golf") magasin02 = Magasin ("Golftown") magasin03 = Magasin ("PointGolf") item01 = Item ("Ensemble de fers Titleist") item01.set_prix("1099.99") item02 = Item ("Ensemble de fers Callaway") item02.set_prix("1299.99") item03 = Item ("Ensemble de fers Taylormade Burner Graphite") item03.set_prix("2499.99") item04 = Item ("Ensemble de fers Cobra") item04.set_prix("999.99") item05 = Item ("Ensemble de fers Ping") item06.set_prix("1399.99") item06 = Item ("Ensemble de fers Ben Hogan") item06.set_prix("1199.99") items = [item01, item02, item03, item04, item05, item06] magasin01.set_items(items) self.set_magasins([magasin01]) self.sauvegarder() def afficher(self): print("") print("Magasins") for magasin in self.magasins: print("") print(magasin) for item in magasin.items: print(item) if __name__ == '__main__': modele = Modele() nom_fichier = "magasinmodele.txt" modele.charger(nom_fichier) if modele.vide(): modele.initialiser(nom_fichier) modele.afficher() And here's my error : Traceback (most recent call last): File "F:\School\University\Session 4\Programmation SIO\magasingolfmodele.py", line 187, in <module> modele = Modele() TypeError: __init__() takes at least 2 arguments (1 given) Thank You!!! -- Marc-O. Rompré
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor