Reputation: 27
I am looking to fetch employee shift details (for 7 days) which works well ; however, the each row ends with ",". I am looking to delete "," so that I can copy those results to tkinter entry boxes.
def showRecord():
connection = sqlite3.connect("C:\Projects\Advisor Roster Swap\employee.db")
connection.text_factory = sqlite3.OptimizedUnicode
cursor = connection.cursor()
cursor.execute('''SELECT "Scheduled Shift" FROM employee_details WHERE Ecode = "5568328"''')
items = cursor.fetchall()
print(items)
connection.close()
The result looks like : [('WO',), ('10:30 - 19:30',), ('10:30 - 19:30',), ('10:30 - 19:30',), ('10:30 - 19:30',), ('10:30 - 19:30',), ('WO',)]
I need to delete the extra ",". Any help is welcome.
Upvotes: 0
Views: 29
Reputation: 617
items
is a list of tuples, the comma is only shown when printing it. If you want to get the column value for the n
th row, items[n - 1]
will give you a tuple containing just the value: ("WO",)
. To then get the value in the tuple use items[n - 1][0]
. You can wrap this in to a comprehension:
items = [i[0] for i in items]
Upvotes: 2