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 8630803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:07:36+00:00 2026-06-12T09:07:36+00:00

I have created a base class: class Thing(): def __init__(self, name): self.name = name

  • 0

I have created a base class:

class Thing():
    def __init__(self, name):
        self.name = name

I want to extend the class and add to the init method so the that SubThing has both a name and a time property. How do I do it?

class SubThing(Thing):
    # something here to extend the init and add a "time" property

    def __repr__(self):
        return '<%s %s>' % (self.name, self.time)

Any help would be awesome.

  • 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-06-12T09:07:36+00:00Added an answer on June 12, 2026 at 9:07 am

    You can just define __init__ in the subclass and call super to call the parents’ __init__ methods appropriately:

    class SubThing(Thing):
        def __init__(self, *args, **kwargs):
            super(SubThing, self).__init__(*args, **kwargs)
            self.time = datetime.now()
    

    If you’re still on Python 2.x, make sure the base class is a subclass of object, as super won’t work with old-style classes:

    class Thing(object):
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base class like this: class base(object): name = def __init__(self,name): self.user
I have created a gem that adds a new method to the class ActiveRecord::Base.
I have the following: module Thing def self.included(base) base.send :extend, ClassMethods end module ClassMethods
I have a model, for example : class Account < ActiveRecord::Base before_create :build_dependencies def
I have created a data base that comes in an installer that runs as
I have something like this: class Person < ActiveRecord::Base has_many :things do def [](kind)
I have created an app targeted for ios 4.1 with base SDK ios 5.0
I have introduced boost to our code base, on my machine I created a
So in my base template, I have: {% render EcsCrmBundle:Module:checkClock %} Then I created
I have controller with action new , and I want it to create ActiveRecord::Base

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.