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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:44:59+00:00 2026-06-07T19:44:59+00:00

class Method(object): def __call__(self): #how could I get the App instance here? return True

  • 0
 class Method(object):
     def __call__(self):
         #how could I get the App instance here?
         return True

 class App(object):
     def __init__(self):
         self.g = Method()

As you can see, the above code can explain my question.

  • 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-07T19:45:01+00:00Added an answer on June 7, 2026 at 7:45 pm

    You’d have to store a pointer back to the App object in the Method:

    class Method(object):
        def __init__(self, app):
            self.app = app
    
        def __call__(self):
            self.app.something()
            return True
    
    class App(object):
        def __init__(self):
            self.g = Method(self)
    

    If you have an absolute need to avoid passing the self pointer in App, you’ll need to inspect the stack to retrieve it instead.

    The following is discouraged and only works when you instantiate Method objects in a method of App:

    import sys
    
    class Method(object):
        def __init__(self):
            parent = sys._getframe(1) # Calling context
            locals_ = frame.f_locals
            assert ('self' in locals_,
                'Method objects can only be instanciated inside instance methods')
            self.app = locals_['self']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given is the following example: class Foo(object): def __init__(self, value=0): self.value=value def __int__(self): return
mod1.py import mod2 class Universe: def __init__(self): pass def answer(self): return 42 u =
I have two classes like the following: class Super(object): def __init__(self, arg): self.arg =
I have a __new__ method as follows: class MyClass(object): def __new__(cls, *args): new_args =
I have a class with like 50 methods. class MyProgram(object): def method1(self): pass def
I've a method in a class that get's a pointer to another object (of
Why can't I use super to get a method of a class's superclass? Example:
Controller Call user = User.authenticate(params[:session][:email], params[:session][:password]) Authenticate Method in user.rb class << self def
I have the following IronPython code. class Hello: def __init__(self): pass def add(self, x,
Currently, I'm doing it in this fashion: class Spam(object): decorated = None @classmethod def

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.