sqlstring = 'INSERT INTO {}'
table = 'Product'
sqlstring.format(table)
does not result to ‘INSERT INTO Product’ but still ‘INSERT INTO {}’ why is this so?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Python 3.2 does this correctly:
What version are you using?
Additional thought:
Strings are immutable and do not self-modify in-place. Maybe you want:
If format strings self-modified themselves in place it would be quite annoying for Python programmers, as each format string could only be used once. Sometimes we want the chance to build a nice format string then use it hundreds of times — which is easy if
format()returns the result instead of modifying the format in-place.