473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Understanding __call__ in Python 3

I am reading a Python book for Pyton 2.5 (But I am doing Python 3). I am at the chapter classes and I got this part;

"You can check whenever the function attribute was callable."

Expand|Select|Wrap|Line Numbers
  1. callable(tc,'talk',None)
In Python3 we do not have callable anymore, so I checked on the internet, how do it, and I found this:

Expand|Select|Wrap|Line Numbers
  1. hasattr(anything, '__call__')
Now here are my question:

1.) What do I have to put in the "anything" part? a function of a class?

2.) What does callable actually do? What does callable actually means? To check when was the last time I used that function..? What does it do? And what kind of situatins would I use this?

Thanks in advance
May 18 '11 #1
2 3326
dwblas
626 Expert 512MB
This has already been answered in another forum.
May 18 '11 #2
bvdet
2,851 Expert Mod 2GB
"A function call is an expression containing a simple type name and a parenthesized argument list."

Builtin function callable() returns True if an object has a __call__ method or False if not.
Expand|Select|Wrap|Line Numbers
  1. >>> callable
  2. <built-in function callable>
  3. >>> callable(str)
  4. True
  5. >>> hasattr(str, "__call__")
  6. True
  7. >>> x = 10
  8. >>> callable(x)
  9. False
  10. >>> 
May 23 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: chris | last post by:
Have a COM object that needs to call python scripts/libs. Can this be easily done? thanks. chris
4
by: paritosh mahana | last post by:
Hi all, How can I call python code from my C# code. One thing is to make an ..exe file of the python program and then try to call it from my C# code. But I don't like that idea. Is there any...
0
by: sdhyok | last post by:
PyMat enables to call matlab functions from python. But, what I want is to call python functions from matlab. Is there any library for it? Thanks. Daehyok Shin
2
by: Sibou51 | last post by:
Hello everybody, do you know if it's possible to call a python script in html page?? I want call my script pyhton and I have a html with javascript but I don't know how, do you have an...
3
by: cdd | last post by:
Hi, I have a perl script that is running in windows environment. This is calling python BodyTextExtractor. My problem is: I have to move the script to run on linux and I have to change the...
3
by: Allen | last post by:
I use try catch, but cannot catch the execeptions of execution python method. PYCALL_API void PyCall(const char * pszModule, const char * pszFunc, void * pArg) { if (pszModule == NULL ||...
1
by: parthpatel | last post by:
See i need to call the python function from javascript in html Is it possible to do so ??
3
by: parthpatel | last post by:
hello how can i call python function from xul ??? i m trying to call python from xul how can i do that ??
15
by: silverburgh.meryl | last post by:
Hi, I am trying to understand the following line: # a is an integer array max(), (j,i)) Can you please tell me what that means, I think sum(a means find the some from a to a But what is...
1
by: hofsoc20 | last post by:
Hi, I am trying to call a python script (Python 2.5) and implement one of its functions. I have successfully called the script and executed it with jep.runscript("sample.py"). Does anyone...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.