0

I haven't found anything near a solution yet, if you could at least give me a clue.. I have this function:

def analizar_consulta(consulta, v):
    print('\ntomar consulta: {}\n'.format(consulta))
    #transformar todas las variables en su contenido
    consulta = transformar_variable(consulta, v)
    if consulta[0] in diccionario_funciones.keys():
        parametros = list(filter(lambda x: not(isinstance(x,list)), consulta[1:]))
        consultas = list(filter( lambda x: isinstance(x,list) , consulta[1:]))
        print('parametros: {}'.format(parametros))
        print('consultas: {}\n'.format(consultas))
        if len(consultas) > 0:
            pasadas = list(map(lambda x: analizar_consulta(x, v), consultas))
            parametros.append(pasadas)
        else:
            return diccionario_funciones[consulta[0]](*parametros)
        return diccionario_funciones[consulta[0]](*parametros)
    else:
        raise Exception('Comando no encontrado')

as it is recursive, sometimes it takes arguments from inside the first parameter as a new parameter for itself in a new instance, but sometimes the first argument of the new parameters is a list, which raise an error on the line 5 (consulta[0]) Is there a way to, if there is a list (which only contain numbers), it just returns it instead of continuing with the rest of the code? Sorry for the code is in Spanish, if you don't understand something I can edit it.

when I try it whit ["comparar", ["PROM", "x"], ">", ["DESV", "y"]] this parameter, it raises the error: TypeError: unhashable type: 'list'

2
  • Please fix your indentation. Commented May 5, 2017 at 14:48
  • 2
    Instead of saying "which raise an error on the line 5" you should say what error it raises. Ideally post the complete error traceback. Commented May 5, 2017 at 14:50

1 Answer 1

1

Technically, yes. Add at line 4.5:

c0 = consulta[0]
if isinstance(c0, list) and all(isinstance(i, int) for i in c0):
    return

That having been said, the fact that you don't know what your parameter list contains indicates that there's a design problem in your code. You just called a function to do some kind of transformation on your list:

consulta = transformar_variable(consulta, v)

Why didn't you fix it?

Consider taking a look at the overall code, and asking a different question on SO: "How can I do (whatever it is)?"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.