parsing - How to write a small tokenizer in Python? -


this question has answer here:

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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -