如何使用SQLite列字符串值作为Python数组的输入?
我有一个带有以下列的sqlite表,
DATE SYMBOL NAME
timestamp1 XYZ ABC
timestamp2 YYZ XBC
...
我的程序更长,该程序在这样的python数组中采用输入值。
mynames = ['ABC', 'BBC', ...]
我的问题是如何将列值ABC
,XBC
等等,然后将其用作上述数组的输入。这是我现在拥有的;
def get_Data():
# from math import *
data = cursor.execute(''' SELECT * FROM databaseName ORDER BY NAME''')
for record in data:
print ('Timestamp: '+str(record[0]))
print ('Symbol: '+str(record[1]))
print ('Name: '+str(record[2]))+'\n')
请注意,我需要围绕列值添加的引号。做这件事的最有效方法是什么?
I have a Sqlite table with the following columns
DATE SYMBOL NAME
timestamp1 XYZ ABC
timestamp2 YYZ XBC
...
I have a longer program, which takes input values in a Python Array like this;
mynames = ['ABC', 'BBC', ...]
My question is how to take the column values ABC
, XBC
and so on and use it as input to the aforementioned array. Here's what I have right now;
def get_Data():
# from math import *
data = cursor.execute(''' SELECT * FROM databaseName ORDER BY NAME''')
for record in data:
print ('Timestamp: '+str(record[0]))
print ('Symbol: '+str(record[1]))
print ('Name: '+str(record[2]))+'\n')
Please note I need the quotes added around the column values. What's the most efficient way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我用这个解决了这个问题。但是,我不确定这是否是最有效的方法。
I fixed this with this. However, I am not sure if this is the most efficient way.