2

How can I get my output in the table?

from prettytable import PrettyTable
import sqlite3

x = PrettyTable(["URL"])
x.padding_width = 1 

con = sqlite3.connect('C:\\Users\\joey\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\History')
cursor = con.cursor()
d = cursor.execute("SELECT URL FROM 'urls' ;")
for data in d:
    x.add_row([data])


print(x)

How can I add the output of my code in the table? This code is not working. The code under this text is good. But how can I get my output in this and not the "test".

x = PrettyTable(["URL"])
x.padding_width = 1 

x.add_row(["test"])
hitzg
  • 12,133
  • 52
  • 54
joey
  • 241
  • 1
  • 4
  • 16

1 Answers1

3

The cursor returns tuples as you iterate over it. So instead of [data] (which would be a list containing a tuple), pass data itself to add_row:

for data in cursor:
    x.add_row(data)
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
  • Hey Thanks for helping me! The output is really messy It doenst really like a table anymore haha. '+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------' Is kinda how my output looks now – joey Jun 11 '15 at 12:11