[英]SQLite3 Queries
I am looking to fetch employee shift details (for 7 days) which works well;我正在寻找运行良好的员工轮班详细信息(7 天); however, the each row ends with ",".但是,每一行都以“,”结尾。 I am looking to delete "," so that I can copy those results to tkinter entry boxes.我希望删除“,”以便将这些结果复制到 tkinter 输入框。
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',)]结果如下所示: [('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.欢迎任何帮助。
items
is a list of tuples, the comma is only shown when printing it. items
是一个元组列表,逗号仅在打印时显示。 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",)
.如果您想获取第n
行的列值, items[n - 1]
将为您提供一个仅包含值的元组: ("WO",)
。 To then get the value in the tuple use items[n - 1][0]
.然后使用items[n - 1][0]
获取元组中的值。 You can wrap this in to a comprehension:你可以把它包装成一个理解:
items = [i[0] for i in items]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.