tags:

views:

819

answers:

3

I have rows in file like :

20040701         0  20040701         0      1  52.965366  61.777687  57.540783

I want to put that in a dynamic array if it's possible ?

Something like

try:
    clients = [
        (107, "Ella", "Fitzgerald"),
        (108, "Louis", "Armstrong"),
        (109, "Miles", "Davis")
        ]
    cur.executemany("INSERT INTO clients (id, firstname, lastname) \
        VALUES (?, ?, ?)", clients )
except:
    pass
+2  A: 

You can easily make a list of numbers from a string like your first example, just [float(x) for x in thestring.split()] -- but the "Something like" is nothing like the first example and appears to have nothing to do with the question's Subject.

Alex Martelli
+1  A: 
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 that the kind of thing you're looking for? I'm not certain from your question.

mavnn
+1  A: 

From my reading for your question, I think you want something like:

rows=[map(Decimal,x.split(' ')) for x in lines]
lostlogic