[英]Converting from Tuple to List to modify in Python
我正在查詢Oracle數據庫,並且需要對作為Clob的一列數據進行一些特殊處理。 我可以使用.read()
讀取.read()
。 我想將實際值寫回到我的數組。 這是一個元組,因此我必須轉換為列表,寫入值,然后再轉換回元組。 我收到錯誤消息: TypeError: 'tuple' object does not support item assignment
我的代碼:
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
試試這個
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.