Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can i parse my output?
#5
(Mar-16-2022, 02:39 PM)ilknurg Wrote: I have no idea, how should i get ou's and save it to database
Have 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'}
Reply


Messages In This Thread
How can i parse my output? - by ilknurg - Mar-16-2022, 08:39 AM
RE: How can i parse my output? - by Gribouillis - Mar-16-2022, 09:03 AM
RE: How can i parse my output? - by ilknurg - Mar-16-2022, 02:39 PM
RE: How can i parse my output? - by Gribouillis - Mar-16-2022, 03:00 PM
RE: How can i parse my output? - by snippsat - Mar-16-2022, 03:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can i parse my output? ilknurg 20 3,486 Mar-10-2022, 02:19 PM
Last Post: ilknurg
  Unable to parse JSON output dragan979 1 3,583 Apr-20-2018, 02:24 PM
Last Post: dragan979

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020