2016-04-20 34 views
-1

當在python中使用cx_oracle模塊時,當我運行查詢並打印輸出時,它將它作爲元組對象。然而,我想輸出作爲一個字典對象,它整齊地: {,'',,'',,'',}使用cx_Oracle轉換查詢輸出到冠詞對象

有一個快速的事情,我可以做到這一點?

回答

0

我想出了一個方法來做到這一點。下面是相關的代碼片段:

column_name = [column1,column2,column3] 
for row in cur: 
     list_row = list(row) # convert the tuple row to a list type. 
     final = zip(column_names,list_row) # zip the two lists. 
     dict_final = dict(final) # Convert the resulting final list to a dictionary. 

我不知道是否有更好的方法來做到這一點,但這就是我想出的。