0

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
1
  • 1
    What does the insert statement have to do with the list of numeric values? Can you expand on your question so that there's some logical connection between the two parts. Commented May 21, 2009 at 15:28

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2
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.

Comments

1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.