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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:50:57+00:00 2026-06-14T17:50:57+00:00

What is happening here? What do the brackets do here test2 = A() ?

  • 0

What is happening here?

What do the brackets do here test2 = A()?

How can I make object A() callable.

class A(object):
    @property
    def a(self):
        "an important attribute"
        return ["a value","dsfsdfsd"]

test1 = A

test2 = A()


print test1().a                                

print test2().a      
  • 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-14T17:50:58+00:00Added an answer on June 14, 2026 at 5:50 pm

    (I’ve edited my previous anwser, which was working but as pointed out, not really a good practice)

    There is slight confusion between object representation in Python here :

    test1 = A 
    print test1 #return : <class '__main__.A'>
    

    In python you can copy a class, because a class in also an object in Python. You can see as an alias, but it is more useful than that.

    test2 = A() 
    print test2 #return : <__main__.A object at 0x0126DF90>
    

    Here you have created an A object at a certain adress.

    print test1().a
    

    What you are doing is in reality : A().a . In other word you create a temporary object and then call the a property. It works in your example but it is not more useful than a static method since the object is temporary (usually class methods take are used to view/modify an object’s internal state).

    print test2().a # == [A()]().a
    This does not work because you want to call an object as a method. To do so you have to add a __call__ special method in the class description. If your a property is important, that’s what I would do :

    class State(object):
        " Dummy Finite state machine "
    
        def __init__(self)
             self.count = 0
    
        @property
        def state(self):
            return self.count % 4
    
        def __call__(self):
            return self.state
    
        def next(self):
            self.count +=1
    
    s = State() # State object
    print s() # return 0
    s.next() # count = 1
    s.next() # count = 2
    s.next() # count = 3
    s.next() # count = 4
    s.next() # count = 5
    print s() # return 5 % 4 =1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone explain what is happening here? class Test(object): __getitem__ = getattr t =
I can't capture what is happening here. My global.asax file has nothing exotic in
Can anyone tell me what is happening here? <?php // true var_dump('\\ ' ===
I am hoping that someone can clarify what is happening here for me. I
Can someone help me explain what is happening here? Sorry if this is a
I don't understand what's happening here. Logically, it doesn't make any sense to me.
I'm curious as to what's happening here. Can someone who knows generators and coroutines
Can you please explain to me what is happening here? char data[128]; // Create
You can see it happening here: http://www.smooth-media.co.uk/clients/BCD
I am not sure what's happening here...but say I do this: def who_wins?(choice1, choice2)

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.