Yet Another MySQL Problem

Victor Subervi victorsubervi at gmail.com
Thu May 27 14:00:15 EDT 2010


On Thu, May 27, 2010 at 12:56 PM, MRAB <python at mrabarnett.plus.com> wrote:

> Kushal Kumaran wrote:
> [snip]
>
>  Since I'm in a good mood today, here's a little present:
>>
>> def insert(cursor, table, columns, values):
>>    """Insert a row into a table.  columns must be a list of column
>>    names.  values must be a list of values for the new row.  The
>>    columns and values must correspond."""
>>    assert len(columns) == len(values)
>>
>>    stmt = """
>> insert into %s (%s) values (%s)
>> """ % (table,
>>       ', '.join(columns),
>>       ', '.join('%s' * len(values)))
>>
>
> That should be:
>
>
>       ', '.join(['%s'] * len(values)))
>
>     logging.debug('stmt: %s, values: %s' % (stmt, values))
>>
>>    cursor.execute(stmt, values)
>>
>> Hope it helps.
>>
>> Yes it did. Thanks. Also figured out the "import logging" :-}
beno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100527/09988980/attachment-0001.html>


More information about the Python-list mailing list