I have a function or query to execute. The query is in form of a string(within single quotes).Now, how to unmask the query from string form & execute

Viewed 24
s='Search(using=client, index="5").query("match",Job_Title=Sales Executive).query("match",Job_Group=Sales).query("match",Job_State=Karnataka).query("match",Skills_Required=marketing)'

I want to run response = s.execute()

s is the Elastic search query within a single quote in form of a single string. I want to execute it, But it will get executed only i can unmask it from the string form to function form.How do i do it.

1 Answers

What you're probably looking for is pythons built-in eval() method. It evaluates a string expression and returns to you the result. Usage:

response = eval(s)

Before you decide to use eval however, first see why using eval might be dangerous and why ast.literal_eval() should be preferred.

Related