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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:23:58+00:00 2026-05-28T04:23:58+00:00

class Test: def func(): print(‘func’) test1 = Test() test2 = Test() test1.func() #TypeError: fun1()

  • 0
class Test:
       def func():
           print('func')
test1 = Test()
test2 = Test()

test1.func()  #TypeError: fun1() takes no arguments (1 given)
test2.newfunc = Test.func
test2.newfunc()#It goes well

# update part
def foo(self):
    pass
Test.foo = foo
test1.foo # it is bound method
test2.foo = foo
test2.foo # it is function
# end 

Is there any difference between the two ways ?
Thanks.

# update part
def foo(self):
    pass
Test.foo = foo
test1.foo # it is bound method
test2.foo = foo
test2.foo # it is function
# end 

Note that what’s important is that the retrieval should take place in class instead of instance.

  • 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-28T04:23:59+00:00Added an answer on May 28, 2026 at 4:23 am

    A bit of investigation:

    >>> test1.func
    <bound method Test.func of <__main__.Test instance at 0x800f211b8>>
    >>> Test.func
    <unbound method Test.func>
    

    Then user-defined bound method (test1.func in our case) is called, this call is actually performed as Test.func(test1) – class instance is always passed as first argument.

    See much more on this topic in Python Data model.


    Edit

    Output above is from Python 2.6. Since Test.func() works for you, I assume that you are using Python 3. In this case output will be the next:

    >>> test1.func
    <bound method Test.func of <__main__.Test object at 0xb747624c>>
    >>> Test.func
    <function func at 0xb74719ec>
    

    As you see, Test.func is a simple function, so no ‘magic’ will be added while calling it.

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

Sidebar

Related Questions

import inspect class Test: def test(self, p, d={}): d.update(p) return d print inspect.getargspec(getattr(Test, 'test'))[3]
class Test: def c(self, args): print args def b(self, args): args.append('d') def a(self): args
I get this error object has no attribute 'im_func' with this class Test(object): def
i have the following class test hash={} def printHash puts hash[1] puts hash[2] puts
The following code: class MyClass(): def test(self): self.__x = 0 def __setattr__(self, name, value):
How can it be that this test case import unittest class PropTest(unittest.TestCase): def test(self):
Suppose I have a class in Ruby: class Test def method(arg1, arg2) return arg1+arg2
I have the following ruby code: class Mp def initialize Test.new.mytest Work.new.mywork ha address
Try running the following code: class Test(object): def func_accepting_args(self,prop,*args): msg = %s getter/setter got
How can I access instance variable from singleton method? class Test def initialize(a) @a

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.