fetchall to python lists
christensen.jerome at gmail.com
christensen.jerome at gmail.com
Mon Sep 30 11:16:41 EDT 2013
On Monday, September 30, 2013 4:58:25 PM UTC+2, christens... at gmail.com wrote:
> Hi - I have some basic programming experience and new to Python. I have connected to SQL Server as follows:
>
>
>
> import pyodbc
>
> conn = pyodbc.connect('DSN=DBC')
>
> cursor = conn.cursor()
>
> cursor.execute("select measure,fin_year_no,fin_week_no,location_no,value from actual")
>
> result=cursor.fetchall()
>
>
>
> result looks like this:
>
>
>
>
>
>
>
> result[0] - ('2013', 2014, 7, 242, 96064.35)
>
> result[1] - ('2013', 2014, 7, 502, 18444.2)
>
> .... approximately 2m records
>
>
>
> Is there a way to assign the values of result to 5 lists without doing 5 select statments one for each of the colums and then assigning it to a list so that:
>
>
>
> list1[0] = '2013'
>
> list1[1] = 2014
>
> list1[2] = 7
>
> list1[3] = 242
>
> list1[4] = 96064.35
>
>
>
> list2[0] = '2013'
>
> list2[1] = 2014
>
> list2[2] = 7
>
> list2[3] = 502
>
> list2[4] = 18444.2
>
>
>
> and so on ...
>
>
>
> Hope someone can help. Regards Jerome
Thanks Joel did not think it could be so simple!!!
More information about the Python-list
mailing list