[Tkinter-discuss] Is this introspective?
Bob Greschke
bob at greschke.com
Fri Jul 4 04:18:01 CEST 2008
On 2008-07-03, at 19:54, Cameron Laird wrote:
>
> 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 ...
>
>
Oh yeah, you're right. Oops. I just wasn't thinking. I'm trying to
make menus that call functions that bring up toplevel frames. Does
that count? ;) globals()! I forgot all about that.
Thanks!
Bob
More information about the Tkinter-discuss
mailing list