【发布时间】:2018-09-23 11:12:51
【问题描述】:
我正在尝试使用 python 从远程 oracle 数据库直接查询的元组列表中的值 '\x1c' 替换为空格 (" ")。我收到此错误:
TypeError: descriptor 'replace' requires a 'str' object but received a 'NoneType '
下面是我正在使用的代码,错误来自的最后一行代码:
connection = cx_Oracle.connect("WELCOME", "welcome", "(ABC)")
cursor = connection.cursor()
querystring = "select CUST_OR_CARD_ID,MESG from tbaadm.rtt where
SYSTEM_DATE_TIME >= '01/JAN/18' and dcc_id='SPR'"
cursor.execute(querystring)
col=cursor.fetchall()
col = [tuple(map(lambda i: str.replace(i, "\x1c"," "), tup)) for tup in col]
【问题讨论】:
-
出于好奇,元组元素的实际数据类型是什么?替换 '\x1c' 的意图听起来像是可能需要解码的字节对象。
-
我很好奇,我的解决方案如何运作?另外如果需要
DataFrame最好不要使用pd.read_sql ?
标签: python oracle pandas numpy