Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6791879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:54:00+00:00 2026-05-26T17:54:00+00:00

I am trying to make a class with generic __init__ values, but have defaults

  • 0

I am trying to make a class with generic __init__ values, but have defaults for its subclasses, as so:

class Enemy:

 def __init__(self, difficulty, power, MaxHP, magic, MaxMP, speed, name):
    self.power = power + 2*difficulty
    self.HP = self.MaxHP = MaxHP + 5*difficulty
    self.magic = magic + 2* difficulty
    self.MP = self.MaxMP = MaxMP + 5*difficulty
class Goblin(Enemy):
 def __init_(self, difficulty = 1, power = 1, MaxHP = 5, magic = 1, MaxMP = 5, speed = 5, name = "Goblin"):
    super(Goblin, self).__init__(self, power, MaxHP, magic, MaxMP, speed, name)

However, when I try to make a Goblin object without the full number of default values (like, I’ll just put in a value for difficulty), it tells me I need the full 8 arguments even though the rest are given default values. Is there any reason I can’t do that or am I doing something wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:54:01+00:00Added an answer on May 26, 2026 at 5:54 pm

    Because you called super(Goblin, self).__init__(self, power, MaxHP, magic, MaxMP, speed, name) without difficulty. You probably also want to inherit like class Enemy(object) to make sure Enemy is a new-style class if you’re on 2.x (which I guess you must be, considering the old way that you’ve used super).

    Here’s a simpler example:

    class Animal(object):
      def __init__(self, talk):
        print '__init__ Animal: ', talk
    
    class Cat(Animal):
      def __init__(self, talk='meow'):
        print '__init__ Cat'
        super(Cat, self).__init__(talk)
    
    if __name__ == '__main__':
      tom = Cat()
    

    Outputs :

    __init__ Cat
    __init__ Animal:  meow
    

    Edit:

    Well if the following doesn’t work, perhaps you have old class definitions cached in your interpreter (try running it on a fresh interpreter).

    class Enemy(object):
      def __init__(self, difficulty, power, MaxHP, magic, MaxMP, speed, name):
        self.power = power + 2*difficulty
        self.HP = self.MaxHP = MaxHP + 5*difficulty
        self.magic = magic + 2* difficulty
        self.MP = self.MaxMP = MaxMP + 5*difficulty
        print 'Raaarghh!! I am the formidable {}.'.format(name)
    
    class Goblin(Enemy):
      def __init__(self, difficulty=1, power=1, MaxHP=5, magic=1, MaxMP=5, speed=5, name="Goblin"):
        super(Goblin, self).__init__(difficulty, power, MaxHP, magic, MaxMP, speed, name)
    
    if __name__ == '__main__':
      g = Goblin(name='user1038783 goblin')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to make a generic class to represent a range of values
I am trying to make a generic method: class Foo attr_reader def add(object) item
I'm trying to make this code generic: public final Object unwrap(Class arg0) { throw
I was trying to make my own class for currencies using longs, but apparently
I'm trying to make a generic class that takes 3 types, either a simple
I've been trying and trying to make my generic extension methods work, but they
I'm learning about generics, so I'm trying to make my own generic array class,
I'm trying to make a generic javascript dialog-class based on JQuery to create div-popups
I am trying to make a Graph class with generic vertices and adjacency lists
I have an extension method I'm trying to make generic, for message passing. public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.