I’m using python 2.7
I’m writing some query in python
q = '''
select * from users where user_name = %(user_name)s and user_email = %(user_email)s
'''
I want to format the string in two step
something like :
q2 = q % {'user_name':'david'}
q3 = q2 % {'user_email':'sss@sss.com'}
The example i wrote is not working. python throws KeyError
is there any other option to perform those tasks?
Use a proper database API.
That said, if you know which keys will be omitted in the first pass, you can do: