I append items from a database to an array, like that (I need the 0 in front):
tmpArray = [0]
sql = "SELECT value FROM employees;"
c.execute(sql)
rows = c.fetchall()
for row in rows:
tmpArray.append([row[0]])
Output is like that:
tmpArray = [0, ["xxx"], ["yyy"], ["zzz"]]
I need the Array surrounded by brackets like that:
tmpArray = [(0, ["xxx"], ["yyy"], ["zzz"])]
How can I achieve this or how can I modify the current array, so I get the result that I want? Thank you for helping. The script that I want to use needs the data exactly like that.
1 Answer 1
You could try with this:
tmpArray = [0, ["xxx"], ["yyy"], ["zzz"]]
tmpArray=[tuple(tmpArray)]
print(tmpArray)
answered Jul 3, 2020 at 23:26
MrNobody33
6,5039 silver badges20 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py
tuple(xs)will convert any list (or rather, iterable)xsto a tuple.