For python, how can I use the application console to execute one of my commands

I apologize if I don’t explain it well enough, but I want to know how I can use my console in my application to enter input like “add 5 4”, so it will actually add 5 + 4 instead of just printing it from. I really need a function that can take the line “add 5 4” and recognize that I started by adding a word.

+3
source share
1 answer

If you want to make a full-fledged interpreter, I would say that you learn pyParsing .

Otherwise,

def parse(string):
    words = string.rsplit()
    if words[0] == "add":
        print int(word[1]) + int(word[2])

parse(raw_input());

Please note that I absolutely do not check for errors; you must have this in your application.

+1
source

All Articles