Oct-25-2020, 07:18 AM
Some extra thoughts on this:
If you are considering to use the split() function,
you might be better off reformatting the input string to "rotate,5"
It's less work, and you will need some extra logic, assuming that there are more commands than just rotate.
There is however another possibility, that does what you want, but it will probably require some rethinking of the function.
Consider this:
This is a potentially dangerous thing, as you allow the user to execute all kinds of commands
that may not be desirable
Paul
If you are considering to use the split() function,
you might be better off reformatting the input string to "rotate,5"
It's less work, and you will need some extra logic, assuming that there are more commands than just rotate.
There is however another possibility, that does what you want, but it will probably require some rethinking of the function.
Consider this:
def add(x): print(x + x) z = input('??? ') eval(z)So, if you input 'add(10) ', it will print "20".
This is a potentially dangerous thing, as you allow the user to execute all kinds of commands
that may not be desirable
Paul