On Thu, Jul 03, 2008 at 07:42:17PM -0600, Bob Greschke wrote: . . . > #! /usr/bin/env python > > def doSomething(): > return > > def doSomethingElse(): > return > > def canWeDoSomethingPopup(): > if 'doSomething() exists': > Add-doSomething-call-to-the-popup() > if 'doSomethingElse() exists': > Add-doSomethingElse()-call-to-the-popup() > return > > mainloop() > > > What's the right way to find out if the function doSomething() is in > this program? I want to make up popup context menus (and menubar > menus too, I guess) based on what functions are available in a given > program. doSomething() may be in one program, but not in another, and > I'd like the list of menu items to handle that automatically. > > Should I use getargspec() from the inspect module and look for the > NameError exception, or just use something like "if doSomething:", or ? . . . This is more a question about Python than Tkinter. While we might do well to move further discussion to comp.lang.tcl (or its mailing-list equivalent), I can provide the highlights here:
if "doSomething" in globals(): ... or import types if "doSomething" in globals() and type(doSomething) == types.FunctionType: ... or import types if "doSomething" in globals() and \ type(globals()["doSomething"]) == types.FunctionType: ... or ... _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss