[wxPython-users] Many Similar Dialogs For Date Entry

Paul Koning pkoning at equallogic.com
Fri Feb 2 13:10:24 PST 2007


>>>>> "Rich" == Rich Shepard <rshepard at appl-ecosys.com> writes:

 Rich> On Fri, 2 Feb 2007, Paul Koning wrote:
 >> If your inputs are strings of the right form (or can be turned
 >> into such strings), you can use them to construct function (or
 >> method) names directly:
 >> 
 >> def process(cmd): action = globals().get("process_cmd_%s" % cmd)
 >> if not action: print "Invalid command" return action ()

 Rich> Paul,

 Rich> Yes, they are strings; choices from a wx.RadioBox(). This would
 Rich> save one step since a dictionary would end up calling a
 Rich> function in any case. No?

The approach of creating function names directly from the "switch"
inputs works so long as the strings are limited to valid Python symbol
name constituents.  For example, strings with spaces or periods in
them would not work, nor strings with unprintable characters or
non-ASCII Unicode.

(I once worked around that by creating alternate names in the class
dictionary, via a metaclass, but that's going a bit far for most
purposes... :-) )

	    paul





More information about the wxpython-users mailing list