gpt4 book ai didi

python - 对象没有属性chercher_canal

转载 作者:行者123 更新时间:2023-12-03 08:50:04 24 4
gpt4 key购买 nike

您好,在尝试我的代码时收到此错误:
任何帮助感激

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'



代码本身:
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_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_canal(p_poste)
另外,我不确定100%,但也许您想使用 i而不是 p_poste吗?

关于python - 对象没有属性chercher_canal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43457826/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com