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

  • Home
  • SEARCH
  • 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 4556986
In Process

The Archive Base Latest Questions

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

This is going to be difficult to explain, but what I’m trying to do

  • 0

This is going to be difficult to explain, but what I’m trying to do is create a Base object to base other objects on. The Base class handles shared tasks so that subclasses don’t need to keep implementing them. However, I also need a static/class method which creates instances of the classes. So for example, this is my Base class:

class Base(object):
    def __init__(self, service, reference, vo=None):
        self.service = service
        self.reference = reference
        self.id = reference.getId()
        self.name = reference.getName()
        # do a database lookup here to get more information

    @staticmethod
    def get_objects(service, references, as_dict=False):
        """
        More efficient way to get multiple objects at once. Requires the service
        instance and a list or tuple of references.
        """
        vo_list = database.get_objects_from_references(references)
        items = list()
        for vo in vo_list:
            items.append(Base(service, vo.getRef(), vo))

        return items

The get_objects() method will take a list of ID numbers of entries stored in a database, then get all those objects and make objects out of them in one shot instead of hitting the database for each ID. The problem I’m having is that I have to use Base() in that method to instantiate the class. But this instantiates the Base class, not the subclass:

class Something(Base):
    def __init__(self, service, reference, vo=None):
        Base.__init__(self, service, reference, vo)
        do_extra_stuff()

My problem is I don’t know if I do this:

Something.get_objects(service, references)

Will that just run Base’s init() method, or will it run the subclass’s init() method (and the do_extra_stuff() method)?

  • 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-21T17:26:40+00:00Added an answer on May 21, 2026 at 5:26 pm

    You want a class method instead, that will get the class object as its first parameter so that you can build an instance of that specific class:

    @classmethod
    def get_objects(cls, service, references, as_dict=False):
        """
        More efficient way to get multiple objects at once. Requires the service
        instance and a list or tuple of references.
        """
        vo_list = database.get_objects_from_references(references)
        items = list()
        for vo in vo_list:
            items.append(cls(service, vo.getRef(), vo))
    
        return items
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This will be a bit difficult to explain but I will try my best.
Ok this is really difficult to explain in English, so I'll just give an
I am not sure I am going to be able to explain this one
I shall attempt to explain the scenario. I have a gridview I wish to
I've run into an issue where instanceof works, and then it doesn't. Going into
I suppose similar questions were already asked, but I was unable to find any.
I'm trying to paginate an image gallery using jquery. The image directory I'm using
We just came across this in an old production stored proc (there is a
This question is exactly like this question: How to get MAC address of your
I'm going to make WP widget plugin and want to make it theme independent.

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.