Reproduce a C function pointer array in Python -


i have python program asking user input shell, , if detect specific keywords want go inside specific functions.

the thing avoid doing lot of if , else if. in c avoid situation use function pointer array travel while , use strcmp check input.

i know how in python if possible.

in python use dictionary.

example:

keyword2func = {     "word1": function_word1,     "word2": function_word2, }  word = input("") keyword2func[word]() 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -