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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:24:29+00:00 2026-05-14T07:24:29+00:00

I get this error object has no attribute ‘im_func’ with this class Test(object): def

  • 0

I get this error

object has no attribute 'im_func'

with this

class Test(object):
    def __init__(self, f):
        self.func = f

    def __call__( self, *args ):
        return self.func(*args)

pylons code:

class TestController(BaseController):

    @Test
    def index(self):
        return 'hello world'

full error:

File '/env/lib/python2.5/site-packages/WebError-0.10.2-py2.5.egg/weberror/evalexception.py', line 431 in respond
  app_iter = self.application(environ, detect_start_response)
File '/env/lib/python2.5/site-packages/repoze.who-1.0.18-py2.5.egg/repoze/who/middleware.py', line 107 in __call__
  app_iter = app(environ, wrapper.wrap_start_response)
File '/env/lib/python2.5/site-packages/Beaker-1.5.3-py2.5.egg/beaker/middleware.py', line 73 in __call__
  return self.app(environ, start_response)
File '/env/lib/python2.5/site-packages/Beaker-1.5.3-py2.5.egg/beaker/middleware.py', line 152 in __call__
  return self.wrap_app(environ, session_start_response)
File '/env/lib/python2.5/site-packages/Routes-1.10.3-py2.5.egg/routes/middleware.py', line 130 in __call__
  response = self.app(environ, start_response)
File '/env/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/wsgiapp.py', line 125 in __call__
  response = self.dispatch(controller, environ, start_response)
File '/env/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/wsgiapp.py', line 324 in dispatch
  return controller(environ, start_response)
File '/project/lib/base.py', line 18 in __call__
  return WSGIController.__call__(self, environ, start_response)
File '/env/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py', line 221 in __call__
  response = self._dispatch_call()
File '/env/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py', line 172 in _dispatch_call
  response = self._inspect_call(func)
File '/env/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py', line 80 in _inspect_call
  argspec = cached_argspecs[func.im_func]
AttributeError: 'Test' object has no attribute 'im_func'
  • 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-14T07:24:30+00:00Added an answer on May 14, 2026 at 7:24 am

    TestController.index ends up an instance of Test, with no access to the TestController object. Also, only user defined methods (which must be functions, not objects) have an im_func attribute. You’ll need to instantiate Test and have its __call__ method return a function so that it can be passed the TestController instance.

    class Test(object):
        def __call__( self, f):
            def wrapper(self, *args, **kwargs):
                # anything in the old Test.__call__ goes here.
                return f(self, *args, **kwargs)
            return wrapper
    
    class TestController(BaseController):
        @Test()
        def index(self):
            return 'hello world'
    

    What’s happening

    A decorator:

    @decorator
    def foo(...):
    

    is equivalent to:

    def foo(...):
        ...
    foo = decorator(foo)
    

    In your original code,

        @Test
        def index(self):
    

    creates an instance of Test and passes index to the constructor. The resulting object is assigned to the index property of TestController.

    class TestController(BaseController)
        def index(self):
            ...
        index = Test(index)
    

    Test.__call__ doesn’t get invoked until you try to call TestController.index. With tc an instance of TestController, tc.index() is equivalent to tc.index.__call__() or Test.__call__(tc.index).

    The problem is that within the call to Test.__call__, we’ve lost the reference to tc. It didn’t exist when Test.index was defined, so there’s no way of saving it. Moreover, it looks like Pylons performs some magic on the methods and it expects tc.index to be a user defined method (which has an im_func property), not an object (which doesn`t).

    The approach I show you changes when Test.__call__ is invoked and the type of TestController.index.

    class Test(object):
        def __call__( self, f):
            # if done properly, __call__ will get invoked when the decorated method 
            # is defined, not when it's invoked
            print 'Test.__call__'
            def wrapper(self, *args, **kwargs):
                # wrapper will get invoked instead of the decorated method
                print 'wrapper in Test.__call__'
                return f(self, *args, **kwargs)
            return wrapper
    

    The definition of TestController.index is equivalent to:

    class TestController(BaseController):
        def index(self):
            ...
        index = Test()(index) # note: Test.__call__ is invoked here.
        # 'index' is now 'wrapper' from Test.__call__
    
    tc = TestController
    tc.index() # wrapper from Test.__call__ is invoked here
    

    Because TestController.index is a function rather than an object, tc.index() is equivalent to TestController.index(tc), and we don’t lose the reference to tc.

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

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.