pythonlearner
pythonlearner

Reputation: 105

Python:Iterate over the list giving syntax error

I am trying to execute my sql queries available in the below 3 variables. It's working fine when executing individually. For example: db_connection.execute(sales_updation) is working.

kp_updates = ['sales_updation','price_updation','reward updation']

[db_connection.execute(i) for i in kp_updates]

Error: Syntax Error near sales_updation

Please suggest a fix.

Upvotes: 0

Views: 32

Answers (1)

Richa Bhuwania
Richa Bhuwania

Reputation: 178

The above code should work in Python3.0+ Although if you have Python 2.7, then try executing in for loop.

kp_updates=['sales_updation','price_updation','reward updation']

for i in kp_updates: 
    db_connection.execute(i)

Upvotes: 1

Related Questions