Импорт из csv в SQLite3 Python

Содержание
Введение
Пример
Похожие статьи

Введение

В этом примере я импортирую в базу данных sqlite3 товары из онлайн магазина OLDI

Пример

import csv, sqlite3 con = sqlite3.connect('db/oldi.db') cur = con.cursor() cur.execute("CREATE TABLE goods (\ available,\ categoryId,\ currencyId,\ description,\ id,\ model,\ modified_time,\ name,\ oldprice,\ param,\ picture,\ price,\ type,\ typePrefix,\ uri,\ url,\ vendor,\ vendorCode\ )") with open('csv/current.csv', 'r', encoding="utf8") as f: dr = csv.DictReader(f, delimiter=";") to_db = [(i['available'], i['categoryId'], i['currencyId'], i['description'], i['id'], i['model'], i['modified_time'], i['name'], i['oldprice'], i['param'], i['picture'], i['price'], i['type'], i['typePrefix'], i['uri'], i['url'], i['vendor'], i['vendorCode']) for i in dr] cur.executemany("INSERT INTO goods (available,\ categoryId,\ currencyId,\ description,\ id,\ model,\ modified_time,\ name,\ oldprice,\ param,\ picture,\ price,\ type,\ typePrefix,\ uri,\ url,\ vendor,\ vendorCode) VALUES " "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", to_db) con.commit() con.close()

Article author: Andrei Olegovich

Похожие статьи
SQLite3 Python
Реальный пример
Ошибки
Python
Базы данных

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: