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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:18:42+00:00 2026-05-24T19:18:42+00:00

Okay, so I’ve got a class where one of the attributes is a callback

  • 0

Okay, so I’ve got a class where one of the attributes is a callback function. Problem is, whenever I call it from within the class (e.g. as self.function_attr(), it gets passed self as the first argument. Here’s an idea of what I’m working with:

def callback(a, b):
    # do something with a, b

class A:
    def __init__(self, callback):
        self.callback = callback
        self.callback(1, 2) # Raises a TypeError: takes exactly 2 arguments (3 given)

I’m not willing to write each callback function to take self as a first argument. I wrote a decorator that works around the issue:

def callback_decorator(func):
    def newfunc(self, *args, **kw):
        return func(*args, **kw)
    return newfunc

but I’m wondering if there’s anything better.

Basically, my question is, how can I call instance attributes of my class which are functions without them being passed self as the first argument?

  • 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-24T19:18:43+00:00Added an answer on May 24, 2026 at 7:18 pm

    You just need to make it a staticmethod when you bind it to the class.

    def callback(a, b):
        # do something with a, b
    
    class A:
        def __init__(self, callback):
            # now it won't get passed self
            self.callback = staticmethod(callback)
            self.callback(1, 2)
    

    or

    class A:
        def __init__(self, callback):
            self.callback(1, 2)
    
        # now it won't get passed self
        callback = staticmethod(callback)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I got this Tabcontrol containing a ListBox. Now my problem it that I
Okay, so I'm running a small test webserver on my private network. I've got
Okay, this one is pretty obvious to everyone who use Django and frequently asked
Okay, so the answer to my question might not be the problem but here's
Okay, here is one weird bug... In my app, I load multiple xml files.
Okay I have created an application where in one of the screens I have
Okay so I have a simple HTML Input fragment: <input id=txtFirstName type=text class=txtBox runat=server
Okay, I have hundreds of .net controls with text attributes that needs to be
Okay So I create a ListView and my own ListAdapter but whenever I add
Okay I got some good advice for Mobile Detection but still having an issue

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.