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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:43:25+00:00 2026-06-07T10:43:25+00:00

I have a class, whose __init__ function does a bunch of stuff, and that’s

  • 0

I have a class, whose __init__ function does a bunch of stuff, and that’s all I need.

So I really just want to call the __init__ function of this class. How can I do this, without assigning it to a variable?

  • 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-07T10:43:27+00:00Added an answer on June 7, 2026 at 10:43 am

    First of all, this is clearly a design error – that code should just be a standalone function.

    However, there are a couple of ways that you can do this:

    1. Just instantiate as normal – there is no reason you have to assign the result of an expression to a variable. However, this will result in full object construction (and probably destruction shortly thereafter).

      Foo()
      
    2. Call the underlying function:

      Foo.__dict__.get('__init__')(None)
      

    This won’t trigger object construction, but you probably don’t want that. Note that in the example here, I’ve passed None as the value of self. This only works if __init__ does nothing with self (or, handles the case where it is None).

    2a. You could use staticmethod to make this easier:

    In [32]: class Foo(object):
       ....:     @staticmethod
       ....:     def __init__():
       ....:         print "Foo init"
       ....:
    
    In [33]: Foo()
    Foo init
    Out[33]: <django.core.management.commands.shell.Foo at 0x46d49b0>
    
    In [34]: Foo.__init__()
    Foo init
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why does the following program crash? I have a base class whose destructor is
I have class grades that I need to check if a specific grade is
i have a class A that needs to instantiate a second class B, whose
I have a class whose instances need to format output as instructed by the
I have a class whose function defined like this. My intention is to send
I have a class whose instances have attributes that are containers which themselves contain
I want to have an array that is accessible throughout my Objective-C project whose
We have a class whose semantic behaviour is like the following :- struct Sample
I have a class whose constructor takes a const reference to a string. This
I have a class whose functionality I'd like to depend on a set of

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.