SQLite & Python 3.6: Build Database,Table,Insert

preview_player
Показать описание
This video will walk you through how to start from scratch and build a SQLite database, build a table, and insert data into the table all in Python 3.6. We use the SQLite library in Python.

Github Script Repo:

DB Browser:
Рекомендации по теме
Комментарии
Автор

Someone help me out. My only internet is this phone with a cracked screen and this is driving me freaking nuts. Every example I can find online shows INSERTing the data as literals. How can I populate the tables from a Python list...or any variable instead of using quoted strings or absolute values? Here.
On my Pi, in Python, I can't use variables in place of the literal string in the insert statement. Like this. (Assume indents are correct)

import sqlite3

namelist=["Jack", "Charlie", "Ann"]
conn=sqlite3.connect ("data.db")
curs=conn.cursor ()
curs.execute ("""CREATE TABLE IF NOT EXISTS NAMETABLE(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL)""")
# then after commiting ...

n=1
for nm in namelist:
curs.execute ("INSERT INTO NAMETABLE(ID, NAME) VALUES (n, nm)
n+=1


Why won't this work?

jackburnell
Автор

learning python at the moment but am now realising sql is where i should be for storing large amounts of data.
will sql become easier to understand if i learn python first?

snorewak
welcome to shbcf.ru