2017-04-17 34 views
0

hallo im diesen Fehler, wenn mein Code versuchen: Jede Hilfe apreciated thxObjekt hat kein Attribut chercher_canal

File "C:\Users\miky.DESKTOP-70ENDO8\Google Drive\TP2 Programmation orientée objet\TP2_V3\distributeur.py", line 90, in creer_forfait_tv canal = p_poste.chercher_canal() AttributeError: 'list' object has no attribute 'chercher_canal'

der Code selbst:

from canal import Canal 
from forfait_tv import ForfaitTV 
from abonne import Abonne 

class Distributeur: 
#----------- Constructeur ----------------------------- 
def __init__(self): 
    self.__canaux = None 
    self.__forfaits = None 
    #code 
    self.__canaux = [] #list 
    self.__forfaits = [] #list 

#----------- Accesseurs/Mutateurs ---------------------- 
def ajouter_canal(self,un_canal:Canal): 
    self.__canaux.append(un_canal) 


def chercher_canal(self,p_poste:int): 
    postex = None 
    poste_trouve=None 
    lstPoste = [] 
    for i in lstPoste: 
     postex=lstPoste[i] 
     if postex.get_poste()== p_poste: 
      poste_trouve=postex 
      return print(poste_trouve) 

def telecharger_canaux(self,nom_fichier:str): 

    fichierCanaux = open(nom_fichier, "r") 
    for line in fichierCanaux: 
     eleCanal = line.strip(" : ") 
     canal = Canal(eleCanal[0],str(eleCanal[1]),str(eleCanal[2]),eleCanal[3]) 
     self.__canaux.append(canal) 
     return canal 


def sauvegarder_canaux(self, nom_fichier:str): 
    canalx = None 
    numeroPost = None 
    fichCanaux = open(nom_fichier,"w") 
    for i in self.__canaux: 
     numeroPost = i.get_poste() 
     nomPoste = i.get_nom() 
     descPost = i.get_description() 
     couexPost = i.get_cout_extra() 
     fichCanaux.write(str(numeroPost)+ ":" + str(nomPoste) + ":" + str(descPost) + ":" + str(couexPost) + "\n") 

    fichCanaux.close() 



#----------- Opérations -------------------------------- 

def creer_forfait_tv(self, p_nom:str, p_coutBase:float, p_poste:list): 
    forfait = ForfaitTV(p_nom,p_coutBase) 
    self.__forfaits.append(forfait) 
    canal = None 

    for i in p_poste: 
     canal = p_poste.chercher_canal() 
     forfait.ajouter_canal(canal) 

Antwort

0

Das ist, weil Sie keine Methode chercher_canal Aufruf der folgende Code, aber ein Listenattribut:

def creer_forfait_tv(self, p_nom:str, p_coutBase:float, p_poste:list): 
    forfait = ForfaitTV(p_nom,p_coutBase) 
    self.__forfaits.append(forfait) 
    canal = None 

    for i in p_poste: 
     canal = p_poste.chercher_canal() 
     forfait.ajouter_canal(canal) 

Ändern Sie die Zeile auf: canal = chercher_canal(p_poste)

Auch ich bin nicht 100% sicher, aber vielleicht möchten Sie i statt p_poste benutzen?

+0

Danke, ich werde das versuchen –

Verwandte Themen