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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:03:00+00:00 2026-06-02T22:03:00+00:00

In python you can make instances callable by implementing the __call__ method. For example

  • 0

In python you can make instances callable by implementing the __call__ method. For example

class Blah:
    def __call__(self):
        print "hello"

obj = Blah()
obj()

But I can also implement a method of my own, say ‘run’:

class Blah:
    def run(self):
        print "hello"

obj = Blah()
obj.run()

When should I implement __call__?

  • 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-02T22:03:02+00:00Added an answer on June 2, 2026 at 10:03 pm

    This is hard to answer. My opinion is that you should never define __call__ unless your actual goal is to create a function. It’s not something you would do after you’ve already created a traditional object.

    In other words, if you’re starting out thinking “I’m going to create an object” you should never end up implementing __call__. If, on the other hand, you start out thinking “I’m going to create a function… but I wish I could use the object framework to let my function have some state” then you could create the function as an object with state, and define __call__ to make it act like a function.

    I want to include one final bit of advice which was provided by @Paul Manta in a comment to the question, where he wrote:

    If you’re unsure if you need __call__, then you don’t need __call__

    I think that’s sound advice.

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

Sidebar

Related Questions

When creating a class in Python, I can simply make a def __len__(self): method
Lets assume we have a class in python: class A(object): def __del__(self): print Del!
How can I make boost.python code python exceptions aware? For example, int test_for(){ for(;;){
In python, I want to make a class variable static so I can to
I have the following IronPython code. class Hello: def __init__(self): pass def add(self, x,
How i can make some improvement in my IRC client made in Python. The
How can I make a keep alive HTTP request using Python's urllib2?
Possible Duplicate: How can I make an EXE file from a Python program? i
In Python I can use the iterkeys() method to iterate over the keys of
In Python I can use get method to get value from an dictionary without

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.