[wxPython-users] Many Similar Dialogs For Date Entry
Chris Mellon
arkanes at gmail.com
Fri Feb 2 11:57:33 PST 2007
On 2/2/07, Rich Shepard <rshepard at appl-ecosys.com> wrote:
> On Fri, 2 Feb 2007, Don Dwiggins wrote:
>
> >> Perhaps the one dialog class called with named arguments that are used to
> >> present and return only the relevant fields. The dialog class then has a
> >> series of if ... elif control statements.
>
> > Or use a dictionary, keyed on the argument names.
>
> Don,
>
> Please show me an example of how the dictionary would be implemented. It
> looks like something I ought to learn for future reference.
>
> Thanks,
>
Python lacks a case statement, and nestings if/elif can get
cumbersome. The common idiom is to use a dictionary to map values to
callables.
Pseudo C/C+ code:
void processID(int id) {
switch id {
case SWITCH_ONE:
process_one();break;
case SWITCH_TWO:
process_two();break
}
}
Python with nested if:
def processID(id):
if id == SWITCH_ONE:
process_one()
elif id == SWITCH_TWO:
process_two()
Python with dictionary:
def processID(id):
mapper = {
SWITCH_ONE:process_one,
SWITCH_TWO:process_two
}
mapper[id]()
More information about the wxpython-users
mailing list