我正在从Oracle数据库获取数据。一些数据是clob格式的(第8列),因此我必须遍历每一行并进行转换。我想追加将要转换为原始表格的每一行。给我带来麻烦的那条线是Complete_data = [Complete_data, fixed_data]
import cx_Oracle
# USE THIS CONNECTION STRING FOR PRODUCTION
production_username = ''
production_password = ''
con_string = '%s/%s@host' % (production_username, production_password)
con = cx_Oracle.connect(con_string)
cursor = con.cursor()
querystring = ("Select * from SalesDatabase")
cursor.execute(querystring)
data = cursor.fetchall()
#loop through and convert clobs to readable content
for currentrow in data:
Product = currentrow[8].read()
fixed_data = ([currentrow[0], currentrow[1], currentrow[2], currentrow[3], currentrow[4], currentrow[5], currentrow[6], currentrow[7], Product, currentrow[9]])
Complete_data = [Complete_data, fixed_data]
con.close()
print Complete_data
填充列表的常规方法是创建一个append
以其开头的空列表,并在循环中添加项目。
Complete_data = []
for currentrow in data:
Product = currentrow[8].read()
fixed_data = ([currentrow[0], currentrow[1], currentrow[2], currentrow[3], currentrow[4], currentrow[5], currentrow[6], currentrow[7], Product, currentrow[9]])
Complete_data.append(fixed_data)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句