So, I want a simple little application where a user can input a command and its arguments, and then Python will translate that into a defined function and its arguments. For example:
define foo(x,y) bar = x ** y print bar
Then, in a command-line interface, if the user inputs foo 2 3
, I want the program to recognise that and print the result, 8.
Also of note is that it should be able to detect integer arguments, string arguments, and float arguments, without the user hav9ng to specify. As in, if they input foo red 1 2.2
, it can recognise all of red
, 1
, and 2.2
as a string arg, an integer arg, and a float arg of foo
, repsectively.
Research returns the sys.argv
command, but I can't wrap my head around it.
Basically, I'm trying to develop a language within a language. Help?