python - Getting Function name and arguments -


I have come to this situation while writing code in Python for my position and started thinking about this problem.

The problem is given in a string in which the function is named with its logic, how do we get the number of arguments and logic names in the function.

My first thought was:

  s = 'func (a, b)' index = s.find ('(') if (index! = -1) : Arg_list = s [index + 1: -1] .split (',') Func_name = s [: index]   

But as I thought and started, I realized that What function is specified within the function, which has its own logic?

  func1 (func2 (a, b, c), func3 (d, e))   

With the above approach I will end with the correct function name but in arg_list

  ["func2 (a", "b", "c"), "func3" "D", "e")]   

Usually this How to solve the situation?

If your language looks like python, use Ast.parse () :

  Import ast parse (s): tree = ast.parse () print ast.dump (tree) parse ('f , B) ')   

All your required information will be encoded in the tree .

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -