0

I am trying to take a list in python and execute it in MySQL:

list = ['tom', 'larry', 'moe']

select * from test.db where name in (list).

I have tried to ",".join the list but it doesn't seem to work.

What is the correct way I can pass a list into MySQL.

1 Answer 1

2

It seems like you'd want to do something like:

subs = ','.join('%s' for _ in lst)
sql = "select * from test.db where name in ({})".format(subs)
cursor.execute(sql, tuple(subs))
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.