简体   繁体   English

从元组转换为列表以在Python中进行修改

[英]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. 我正在查询Oracle数据库,并且需要对作为Clob的一列数据进行一些特殊处理。 I can read in the clobe with .read() . 我可以使用.read()读取.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 我收到错误消息: 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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