Function lookup using a directory.

Alex Martelli aleaxit at yahoo.com
Mon Jun 18 12:09:53 EDT 2001


<andy.pevy at nokia.com> wrote in message
news:29pX6.14682$cF.320097 at news1.nokia.com...
> Hi Guys
>
> I am having trouble with the directory data type. What I want to

You appear to mean the _dictionary_ data type.

> do is to set up a directory that I can use to parse a command entered by
> the user, and have a directory return the name of a class to handle the
> command.  Like this :-
>
> command_table = {'0':    'Help0',
>             '1':    'Help1',
>             '2':    'Help2',
>             '3':    'Help3' }

Rather than holding the NAMES, which would require further
work to find the class corresponding to a name, hold the CLASS
directly -- move this definition AFTER that of the classes
and change it to:

command_table = {'0':    Help0,
            '1':    Help1,
            '2':    Help2,
            '3':    Help3,
    }


> Can I do this, I.E. have a class as a value in a dictionary

Sure!

> and if so, what would the correct declaration be.

No 'declaration', as you see -- the dictionary-display expression
you used is correct -- just have it hold the classobjects directly
(you'll need to define command_table after the classes are created)
rather than their names.


Alex






More information about the Python-list mailing list