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

php - Wordpress: Link a post to posts of another category manually -

delphi xe7 upload/download dropbox file using the rest client and show progress -

java - Get more than One value and display it -