'How to use Sqlite column string values as input to Python array?
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?
Solution 1:[1]
I fixed this with this. However, I am not sure if this is the most efficient way.
mynames = []
def read_Data():
# from math import *
data = cursor.execute(''' SELECT NAME FROM databaseName WHERE ... ORDER BY ...''')
for record in data:
#print ("'"+str(record[0])+"'"+'\n')
mynames.append("'"+str(record[0])+"'")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Zac1 |
