other ways to check for <type 'function'>?

Fredrik Lundh fredrik at pythonware.com
Thu Nov 2 17:49:19 CET 2006


elderic wrote:

> I never said that I need anything - I merely asked for alternatives. =)
> I'm pretty happy with the types-module or the callable() test.
> 
> Basically it's just for wrapping the creation of Tk-Buttons, etc.
> They need a callback and in my process to learn I wanted to know about
> the possible options to test for that.

the more reason not to even think about using anything but "callable". 
many things in Python are callable; an explicit function test would 
disallow several interesting alternatives:

 >>> def foo():
...     pass
...
 >>> class fum:
...     def bar(self):
...             pass
...     def __call__(self):
...             pass
...
 >>> type(foo) is type(fum)
False
 >>> f = fum()
 >>> type(foo) is type(f)
False
 >>> type(foo) is type(f.bar)
False

etc.

(and I really shouldn't ask why you cannot just use Tkinter, and spend 
your time and energy on something more worthwhile ?  if not else, there 
are plenty of Tk extensions that could need nice wrappers...)

</F>




More information about the Python-list mailing list