错误模块。Python中最多有2个参数错误

2024-10-01 17:21:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我有三门课:否.py, 列表.py以及列表.py在

野都的代号是:

class Nodo:
def __init__(self, dato=None , nodo = None): #@Method
    self._dato = dato
    self._siguiente = nodo
def setDato(self, dato): #@Method
    self._dato = dato
def getDato(self): #@Method
    return self._dato
def setSiguiente(self,nodo): #@Method
    self._siguiente = nodo
def getSiguiente(self): #@Method
    return self._siguiente

Lista的代码是:

^{pr2}$

最后,ListaEnlazada的代码是:

import Nodo
import Lista

class ListaEnlazada(Lista):
def __init__(self): #@Method
    Lista.__init__(self)
    self.__inicio =  None
def esVacia(self): #@Method
    return self.__inicio == None        
def elemento(self,pos): #@Method
    pos = pos-1
    if(self.__inicio == None):
        return  None
    else:
        aux = self.__inicio
        while(aux.getSiguiente() != None and 0<=pos):
            aux = aux.getSiguiente()
            pos -=1
        return aux.getDato()    
def agregar(self,elem,pos): #@Method
    nuevo = Nodo(elem,None)
    if(self.__inicio == None):
        self.__inicio = nuevo
    else:
        aux = self.__inicio
        while(aux.getSiguiente() != None):
            aux = aux.getSiguiente()
        aux.setSiguiente(nuevo)
    self._tamanio +=1        
def eliminar(self,pos): #@Method
    cont = 0
    if(cont == pos):
        self.__inicio = self.__inicio.getSiguiente()
        self._tamanio -=1
    else:
        aux = self.__inicio
        while(True):
            cont += 1
            if(cont==pos):
                aux2 = aux.getSiguiente()
                aux.setSiguiente(aux2.getSiguiente())
                break
            aux = aux.getSiguiente()                
            if(pos<cont):
                print ("fuera de  rango")

当我编译ListaEnlazada时,会得到下一个错误:

TypeError: module.init() takes at most 2 arguments (3 given)

问题是什么?我该怎么解决?在

谢谢!在


Tags: posselfnonereturnifinitdefmethod
1条回答
网友
1楼 · 发布于 2024-10-01 17:21:30

您将一个模块和一个类命名为相同的东西,并且您试图让一个类从一个模块继承,而不是从该模块包含的类继承。在

从类继承:

class ListaEnlazada(Lista.Lista):
    ...

别把Python当作Java来写。如果你真的想把每个类都放在它自己的模块中,至少用小写命名模块,这是Python中的标准约定。混合lista和{}比混合Lista和不同的{}更难。在

相关问题 更多 >

    热门问题