简体   繁体   中英

Converting from Tuple to List to modify in Python

I am querying a Oracle database and need some special handling around one column of data that is a clob. I can read in the clobe with .read() . I'd like to write the actual value back to my array. It's a tuple so I must convert to a list, write the value, then convert back to tuple. I am getting the error message: TypeError: 'tuple' object does not support item assignment

My Code:

import cx_Oracle

# USE THIS CONNECTION STRING FOR PRODUCTION
production_username = 'username'
production_password = 'password'

con_string = '%s/%s@hostname:port/orcl' % (production_username, production_password)
con = cx_Oracle.connect(con_string)
cursor = con.cursor()
querystring = ("Select ID, Description from Table")
cursor.execute(querystring)
data = cursor.fetchall()

for currentrow in range(1, len(data)): 
     description= data[currentrow][1].read()
    data = list(data)
    data[currentrow][1] = description
    data = tuple(data)
con.close()
print data

Try this way

for currentrow in data : 
     description= currentrow[1].read()
     tupled_data= tuple([currentrow[0],description])


print tupled_data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM