Python SQLite3 Tutorial 3 Insering Records Into the Database

preview_player
Показать описание
Hello Everyone my name is Lenny from codewithlennylen254. In this video i'll show you how to start adding data to our database file. Pretty cool stuff to learn.Hope you enjoy.

Links for all the code for this series:

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

first channel i have watched who dont have any ads.

avihk
Автор

Thanks. But what if I want to populate the tables fields from a Python (string) list instead of INSERTing them as static strings in quotation marks? 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
visit shbcf.ru