Fylla databasen

Introduktion till databaser i Python

Jason Myers

Co-Author of Essential SQLAlchemy and Software Engineer

Del 2: fylla databasen

  • Läs in en CSV-fil i en värdelista
values_list = []
for row in csv_reader:
    data = {'state': row[0], 'sex': row[1], 'age': row[2],
            'pop2000': row[3], 'pop2008': row[4]}
    values_list.append(data)
Introduktion till databaser i Python

Del 2: fylla databasen

  • Infoga värdelistan i census-tabellen
from sqlalchemy import insert

stmt = insert(employees)
result_proxy = connection.execute(stmt, values_list) print(result_proxy.rowcount)
2
Introduktion till databaser i Python

Nu kör vi en övning!

Introduktion till databaser i Python

Preparing Video For Download...