0

I've been reading up on string formatting, concatenation, etc in Python and ran into an issue. Given a python object, how come this works in SQLite:

for table in tables:
    query = 'PRAGMA table_info(%s);' % table
    results = connection.execute(query)
    . . .

but this doesn't:

for table in tables:
    query = 'PRAGMA table_info({0});'.format(table)
    results = connection.execute(query)

Error for the second version:

database error: near "(": syntax error
2
  • What does print repr(query) give you? Commented Apr 3, 2014 at 19:31
  • print repr(query) shows something like this: u'PRAGMA table_info(<table_name>);' where <table_name> is something like Cars. Commented Apr 3, 2014 at 19:51

0

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.