Answer the question
In order to leave comments, you need to log in
How can I make the value of a dictionary be of type list?
import sqlite3
conn = sqlite3.connect('arhipT999.db')
cur = conn.cursor()
id = 0
inf = ['rian_ru']
try:
info = cur.execute('SELECT * FROM pr WHERE ch_id=?', (id, ))
if info.fetchone() is None:
cur.execute("""CREATE TABLE IF NOT EXISTS pr(
ch_id INTEGER,
sp TEXT);
""")
conn.commit()
cur.execute('insert into pr values (?, ?)', (id, inf))
conn.commit()
except sqlite3.OperationalError:
cur.execute("""CREATE TABLE IF NOT EXISTS pr(
ch_id INTEGER,
sp TEXT);
""")
conn.commit()
cur.execute('insert into pr values (?, ?)', (id, inf))
print(*cur.execute("SELECT * FROM pr;"))
b = dict(cur.execute("SELECT * FROM pr;"))
print(b)
conn.close()
(0, "['rian_ru']")
{0: "['rian_ru']"}
Answer the question
In order to leave comments, you need to log in
Bring the database schema to normal form . List values must be stored in a separate table and linked through a foreign key.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question