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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:31:26+00:00 2026-05-15T19:31:26+00:00

How would I get return values in this case. (as I would a function)

  • 0

How would I get return values in this case. (as I would a function)

class A(object):
    def __init__(self,a,b):
        self.a = a
        self.b = b
        self.run()
    def run(self):
        return a + b

When I do that I get an instance, how would I get a return value?

Thanks
James

  • 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-15T19:31:26+00:00Added an answer on May 15, 2026 at 7:31 pm

    Are you trying to do something like:

    class A(object):
        def __init__(self,a,b):
            self.a = a
            self.b = b
        def __call__(self):
            return self.a + self.b
    
    a = A(3, 4)
    a() # returns 7
    

    It’s not clear what you want and why. __init__ modifies the self object, but is required to return None (i.e. no return). Anything else will cause a TypeError.

    EDIT: To avoid creating an instance, you can override __new__:

    class A(object):
        def __new__(self,a,b):
            return A.run(a, b);
        @staticmethod
        def run(a, b):
            return a + b
    

    You still haven’t quite explained why you need this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to get the columns that a SQL query would return
I'm looking for a method or an event that would get fired when a
Can someone please shed some light on how I would get this to work:
ByRef vs ByVal generates errors!? I had a method that used an Object Function
Have a look at the following code: class A(object): defaults = {'a': 1} def
I have C function that takes string pointer as a parameter. This functions returns
How would I declare a semantic action that calls a free function that doesn't
In this case, the site is an internal website that is only able to
I have my my model: $this->db->select('companyName,companySlogan,companyContact,companyEmail,companyWebsite,companyPhone,companyFax,companyAddress'); $result = $this->db->get('companyDetails'); How would I return my
I'm doing a $.get() request which returns some HTML. I would like to manipulate

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.