python - Adding column to pyodbc list -


i'm trying add column list returned fetchall() method in pyodbc, giving me error. here code:

import pyodbc import time import calendar datetime import date  #variable declaration today = date.today() beginrange = date(today.year,today.month,1) endrange = date(today.year,today.month,2) #limit data 2 days testing  #connect database connjobdtl = pyodbc.connect("dsn=global_mwm;uid=master") cjobdtl = connjobdtl.cursor()  #database query cjobdtl.execute("select job,suffix,seq,date_sequence,[...]") datajobdtl = cjobdtl.fetchall() cjobdtl.close()  #add column list, date_sequence formatted yyyy-mm datajobdtl = [x + [x[3].strftime("%y-%m")] x in datajobdtl] 

i'm getting error when run script:

file "...\jobdetailscript.py", line 23, in <module>   datajobdtl = [x + [x[3].strftime("%y-%m")] x in datajobdtl] typeerror: unsupported operand type(s) +: 'pyodbc.row' , 'list' 

as test, created representative example in python shell , worked fine, manually created list of lists rather generating list fetchall(). how can resolve error?

it seems straightforward - error message states you're trying + 2 different types of objects. if cast rows lists should work, own ad-hoc testing:

>>>cur.execute('<removed>') #one of own tables >>>tmp = cur.fetchall() >>>type(tmp[0]) #this key!  need change type  <type 'pyodbc.row'>  >>>tt = [1,2,3] >>>tmp[0] + tt #gives same error have  traceback (most recent call last):   file "<pyshell#13>", line 1, in <module> tmp[0] + tt typeerror: unsupported operand type(s) +: 'pyodbc.row' , 'list'  >>>list(tmp[0]) + tt  #returns list wanted  [14520496, ..., 1, 2, 3] 

Comments