How to make dynamic array with different values in Python
I have lines in a file like:
20040701 0 20040701 0 1 52.965366 61.777687 57.540783
I want to put this in a dynamic array if possible?
Sort of
try:
clients = [
(107, "Ella", "Fitzgerald"),
(108, "Louis", "Armstrong"),
(109, "Miles", "Davis")
]
cur.executemany("INSERT INTO clients (id, firstname, lastname) \
VALUES (?, ?, ?)", clients )
except:
pass
0
Jym
a source
to share
3 answers
In [1]: s = "20040701 0 20040701 0 1 52.965366 61.777687 57.540783"
In [2]: strings = s.split(" ")
In [3]: strings
Out[3]: ['20040701', '0', '20040701', '0', '1', '52.965366', '61.777687', '57.540783']
In [6]: tuple(strings)
Out[6]: ('20040701', '0', '20040701', '0', '1', '52.965366', '61.777687', '57.540783')
Is this what you are looking for? I'm not sure about your question.
+2
a source to share