-3

I am trying to display

ID|Class|Start|End|Days|Credit Hours
-------------------------------------
[(1, 'MATH165', '10:30', '11:45', 'M/W/F', '4'), (3, 'MATH165', '10:30', '10:45', 'M/W/F', '4'), (4, 'CSCI230', '4:30', '5:45', 'Tu/Th', '3')]

Like this

ID|Class|Start|End|Days|Credit Hours
-------------------------------------
[(1, 'MATH165', '10:30', '11:45', 'M/W/F', '4'),
(2, 'W131', '4:30', '5:45', 'M/W', '3'),
(3, 'CSCI230', '4:30', '5:45', 'Tu/Th', '3')]

My question: Is it possible to change the format it displays?

  • 1
    Show you code. Use `for` loop to display every row individually. Or generate full string and replace `),` with `),\n`. – furas Dec 06 '16 at 00:57
  • `c = conn.cursor() c.execute("SELECT * FROM Schedule") print(""" """) print("ID|Class|Start|End|Days|Credit Hours") print("-------------------------------------") print(c.fetchall())` – Ocarina of Thyme Dec 06 '16 at 01:38
  • `for row in c.fetchall(): print(row)` or `print(str(c.fetchall()).replace("),", "),\n")` – furas Dec 06 '16 at 01:45

1 Answers1

0

Print every row individually

for row in c.fetchall(): 
    print(row)

or create string using str() and replace ), with ),\n

print( str(c.fetchall()).replace("),", "),\n") )

With first method you can do more - you can use string formatting and it will look nicer.

for row in c.fetchall(): 
    print("{}|{}|{}|{}|{}|{}".format(*row))

See more: PyFormat.info

furas
  • 134,197
  • 12
  • 106
  • 148