On 1 Nov 2005 20:02:41 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> hi
> i have a dictionary defined as
>
> execfunc = { 'key1' : func1 }
##################
def __HELLO(x=' '):
print 'HELLO',x
def __BYE(x=' '):
print 'BYE',x
def __PRINT(x=None, y=None):
print 'PRINT',x,y
cmds = { 'HELLO' : __HELLO,
'BYE' : __BYE,
'PRINT' : __PRINT,
}
a = 'HELLO JOE'
b = a.split()
if cmds.has_key(b[0]):
cmds[b[0]](b[1])
# -> HELLO JOE
cmds[b[0]]()
# -> HELLO
cmds['BYE']('TOM')
# -> BYE TOM
cmds['PRINT']( 'TOM','JOE' )
# -> PRINT TOM JOE
cmds['PRINT']
# -> *No output - No exception
#####################
Inside a class use
cmds = { 'HELLO' : self.__HELLO, # etc
def __HELLO(self, x=' '): #etc
HTH :)
--
http://mail.python.org/mailman/listinfo/python-list