Home Why is a variable in __init__() method not defined in the subclass?
Reply: 0

Why is a variable in __init__() method not defined in the subclass?

user1418 Published in August 15, 2018, 8:44 pm

In subclass ComputerGame, Toy.__init__(self,n), n is undefined.

Why is it warning me that the variable n is undefined when I try to call the __init__() function in the base class? Simply put, why is Toy.__init__(self,n) not callable in the subclass? I have declared ComputerGame (Toy):. Why isn't it inheriting the method Toy.__init__(self,n)?

Should I declare the variable outside the class?

class Toy:
  def __init__(self,n):
    self.__ToyName = n
    self.__ToyID = ""
    self.__Price = 0.00
    self.__MinimumAge = 4

  def SetToyName(self,p):
    self.__ToyName = p
  def SetToyID(self,d):
    self.__ToyID = d
  def SetPrice(self,i):
    self.__Price = i
  def SetMinimumAge(self,i):
    self.__MinimumAge = i
  def GetToyName(self):
    return (self.__ToyName)
  def GetToyID(self):
    return (self.__ToyID)
  def GetPrice(self):
    return (self.__Price)
  def GetMinimumAge(self):
    return (self.__MinimumAge)

class ComputerGame(Toy):
  def __init__(self):
    self.__Catogory = ""
    self.__Console = ""

  def SetCatogory(self,c):
    self.__Catogory = c
  def SetConsole(self,c):
    self.__Console = c
  def GetCatogory(self):
    return (self.__Catogory)
  def GetConsole(self):
    return (self.__Console)
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.29971 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO