Mar-16-2022, 03:27 PM
(Mar-16-2022, 02:39 PM)ilknurg Wrote: I have no idea, how should i get ou's and save it to databaseHave you make it into one string?
To get it database i would use a
dictionary
(as it almost there) or could serialize
(search if you unsure what this mean) it in and back.Using
L
from Grib example.>>> record = dict(L) >>> record {b'CN': b'User1', b'DC': b'local', b'OU': b'GLOBAL'}Into a database example and back to original record.
>>> import sqlite3 >>> >>> conn = sqlite3.connect(':memory:') >>> c = conn.cursor() >>> c.execute("create table Test (key text, value text);") <sqlite3.Cursor object at 0x000002E0047AE1C0> >>> record = {b'CN': b'User1', b'DC': b'local', b'OU': b'GLOBAL'} # Insert the dictionary >>> c.executemany("insert into Test values (?,?);", record.items()) <sqlite3.Cursor object at 0x000002E0047AE1C0> # Get all >>> rec = c.execute("select * from Test;").fetchall() [(b'CN', b'User1'), (b'DC', b'local'), (b'OU', b'GLOBAL')] # Back to start >>> record = dict(rec) >>> record {b'CN': b'User1', b'DC': b'local', b'OU': b'GLOBAL'}