Python 对象没有属性chercher\u canal

Python 对象没有属性chercher\u canal,python,object,error-handling,attributes,Python,Object,Error Handling,Attributes,嗨,我在尝试我的代码时遇到此错误: 有什么特别的帮助吗 文件“C:\Users\miky.DESKTOP-70ENDO8\Google Drive\TP2 Programmation orientée objet\TP2_V3\distributer.py”,第90行,在creer_forfait_tv中 运河=p_poste.chercher_运河() AttributeError:“list”对象没有属性“chercher\u canal” 守则本身: from canal import C

嗨,我在尝试我的代码时遇到此错误: 有什么特别的帮助吗

文件“C:\Users\miky.DESKTOP-70ENDO8\Google Drive\TP2 Programmation orientée objet\TP2_V3\distributer.py”,第90行,在creer_forfait_tv中 运河=p_poste.chercher_运河() AttributeError:“list”对象没有属性“chercher\u canal”

守则本身:

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)

这是因为您在以下代码中调用的不是方法
chercher\u canal
,而是列表属性:

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)
将行更改为:
canal=chercher\u canal(邮政编码)


另外,我不是100%确定,但也许你想用
I
而不是
p\u poste

谢谢,我会试试的