我的代码现在有些问题。一方面,我有一些可以工作的代码,但我认为我可以改进。然而,我试图改进代码的尝试是…灾难性的。这是我的原始代码:
overall_list = []
customer_list = []
if remote_system_id == 'hibiscus' or remote_system_id is None:
hibiscus_cursor.execute(hibiscus_full_SQLstring, hibiscus_parameters)
row = hibiscus_cursor.fetchone()
resultCounter = 0
while row and resultCounter < remote_system_max_results:
customer_list.append({'Hibiscus Customer Number': str(row[0])})
row = hibiscus_cursor.fetchone()
resultCounter += 1
overall_list.append(customer_list)
customer_list = []
if remote_system_id == 'coxcomb' or remote_system_id is None:
coxcomb_cursor.execute(coxcomb_full_SQLstring, coxcomb_parameters)
row = coxcomb_cursor.fetchone()
resultCounter = 0
while row and resultCounter < remote_system_max_results:
customer_list.append({'Coxcomb Customer Number': str(row[0])})
row = coxcomb_cursor.fetchone()
resultCounter += 1
overall_list.append(customer_list)
上面的代码是有效的,但我被告知要对其进行进一步完善。具体来说,我有两个独立的例程来生成输出。我被告知要合并,但结果并不理想:
^{pr2}$上面的代码是我试图改进它,但没有得到好的结果。你知道我为什么会犯这样的错误吗
customer_list.append({'Coxcomb Customer Number': str(row[0])})
TypeError: 'NoneType' object has no attribute '__getitem__'
编辑:
更多的信息。这是两个独立的数据库,彼此之间没有任何关联。它们唯一可能的关系是它们都包含客户信息。连接方式如下:
cnxn = pyodbc.connect(HIBISCUS_CONNECTION)
hibiscus_cursor = cnxn.cursor()
cnxn = pyodbc.connect(COXCOMB_CONNECTION)
coxcomb_cursor = cnxn.cursor()
我在查询这两个数据库,我希望找到类似以下内容:
WHERE firstname LIKE 'adam'
在第一个代码中,它工作得非常好。在第二个例子中,我得到了上面的错误。在
通过以下更改修复:
代码效率低下。可能没用。在
相关问题 更多 >
编程相关推荐