parsing - How to write a small tokenizer in Python? -
this question has answer here:
- can add new statements python's syntax? 13 answers
- mini-languages in python 6 answers
normally, python calls functions by
func(arg0, arg1)
but change to
func arg0 arg1
for example,
#something... cmd = input() interpret(cmd) #something...
if input 'func arg0 arg1'
, expect python execute func(arg0, arg1)
.
args contain string, can't split words.
actually, write scripts use on mobile. little annoying type parentheses.
you can :
class tryclass: def callfunction(self, arg, arg2): print("in call") print(arg) print(arg2) input = str(input()) input = input.split(" ") funcname = input[0] my_cls = tryclass() method = getattr(my_cls, funcname) method(input[1], input[2])
if put in input callfunction hello world works :)
Comments
Post a Comment