如何处理python 3中的“太多参数”错误

问题描述 投票:0回答:1

我试着在这里制作一个玩具类

class Toy:

  def __init__(self,name,ID,price,age):


    self.__ToyName = name  
    self.__ToyID = ID
    self.__Price = price
    self.__MinimumAge = int(age)
##some methods here

当我尝试制作一个子类计算机游戏时,我需要制作7个参数(玩具类中有5个)来实例化计算机游戏类,它显示“太多争论(7/5)”

class ComputerGame(Toy): 
  def __init__(self,name,ID,price,age,catogory,console):

    Toy.__init__(self,name,ID,price,age)
    self.__Catogory = catogory
    self.__Console = console

这种情况我该怎么办?

python python-3.x class variables
1个回答
1
投票

您需要了解更多有关super的信息

class ComputerGame(Toy): 
  def __init__(self, name, ID, price, age, catogory, console):
    super(ComputerGame, self).__init__(name, ID, price, age)
    self.__Catogory = catogory
    self.__Console = console
© www.soinside.com 2019 - 2024. All rights reserved.