I am trying to parse a python script to get the functions names and their arguments, I need to do it using java.
I managed to get their names using Jython but I can't find any way to get their arguments (name, number of them?).
Python example :
def multiply_by_two(number):
"""Returns the given number multiplied by two
The result is always a floating point number.
This keyword fails if the given `number` cannot be converted to number.
"""
return float(number) * 2
def numbers_should_be_equal(first, second):
print '*DEBUG* Got arguments %s and %s' % (first, second)
if float(first) != float(second):
Java code:
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile(file.getAbsolutePath());
PyStringMap map=(PyStringMap)interpreter.getLocals();
for (Object key : map.keys()) {
Object o=map.get(Py.java2py(key));
if (o instanceof PyFunction) {
System.out.println((String)key); // the function name
PyFunction function = (PyFunction) o;
}
}
I start to lose hope about finding a way to do it...
If anyone have an idea, even without using Jython
Thank you