mercredi 29 juillet 2015

Python getting 'sqlite3.OperationalError: table percipitation already exists' my code so far

def create_precipitation(db, data_file):
    """(str, reader) -> NoneType
    Populate the database db with the contents of data_file.
    Create a table called Precipitation, with four columns: City
    (text), Snow (real), Total (integer), Days (integer).

    Parameters:

    db: name/path to a database

    data_file: contains one city, snowfall amount, total
    precipitation amount, and number of days per line, separated by
    comma.
    """  
    conn = sqlite3.connect(db)
    cur = conn.cursor()
    cur.execute('create table percipitation' +
                '(city text, snow real, ' +
                'Total integer, Days integer)')
    for line in data_file:
        values = line.strip().split(',')
        city = values[0]
        snow = float(values [1])
        total = int(values[2])
        days = int(values[3])
        cur.exectue("insert into percipitation values (?,?,?,?)",
                    (city, snow, total, days))
    conn.commit()
    cur.close
    conn.close()

Aucun commentaire:

Enregistrer un commentaire