Function lookup using a directory.
Roman Suzi
rnd at onego.ru
Mon Jun 18 13:08:40 EDT 2001
More information about the Python-list mailing list
Mon Jun 18 13:08:40 EDT 2001
- Previous message (by thread): Function lookup using a directory.
- Next message (by thread): Function lookup using a directory.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, 18 Jun 2001, Roman Suzi wrote: >On Mon, 18 Jun 2001 andy.pevy at nokia.com wrote: > >> Hi Guys >> >> I am having trouble with the directory data type. What I want to >> 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' } >> >> class Help0: >> >> def run(self,which): >> if len(which) == 1: >> print 'Help no args' >> else: >> print 'Help args' >> >> class Help1: >> >> def run(self,which): >> if len(which) == 1: >> print 'Help1 no args' >> else: >> print 'Help1 args' >> >> class Help2: >> >> def run(self,which): >> if len(which) == 1: >> print 'Help2 no args' >> else: >> print 'Help2 args' >> >> class Help3: >> >> def run(self,which): >> if len(which) == 1: >> print 'Help3 no args' >> else: >> print 'Help3 args' > >Brrrr... > >Maybe: > >class Help: > noargs = "no such command" > args = "no such cmd" > > def run(self,which): > if len(which) == 1: > print self.noargs > else: > print self.args > Oops. Forgot to superclass: class Help0(Help): noargs = "blah blah ..." args = "balh x blah y ..." Sincerely yours, Roman Suzi -- _/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/ _/ Monday, June 18, 2001 _/ Powered by Linux RedHat 6.2 _/ _/ "Nostalgia isn't what it used to be." _/
- Previous message (by thread): Function lookup using a directory.
- Next message (by thread): Function lookup using a directory.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list