Database Programming

Aahz Maruch aahz at netcom.com
Tue May 2 20:28:01 EDT 2000


In article <#UCgPEJt$GA.230 at cpmsnbbsa03>,
lexberezhny <lexberezhny at email.msn.com> wrote:
>hi,
>  You can use the 'for' loop:
>
>for item in table:
>    database.query('INSERT INTO format_prices
>(time,open,high,low,close,volume) VALUES
>('+item[0]+','+item[1]+','+item[2]+','+item[3]+','+item[4]+','+item[5]+')')

A better variation on that theme:

for item in table:
  item = tuple(item)
  database.query("""
    INSERT INTO format_prices
    (time, open, high, low, close, volume)
    VALUES ( '%s', '%s', '%s', '%s', '%s', '%s' )
    """ % item)
--
                      --- Aahz (Copyright 2000 by aahz at netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"Laws that restrict speech are an abomination for a simple reason.
They're like a poison gas; they seem to be a good weapon to vanquish
your enemy, but the wind has a way of shifting."  -- Ira Glasser



More information about the Python-list mailing list