[Tkinter-discuss] Is this introspective?

Bob Greschke bob at greschke.com
Fri Jul 4 03:42:17 CEST 2008


#! /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 ?

Thanks!



More information about the Tkinter-discuss mailing list