我使用pymssql庫查詢的結果刪除的數據類型,這裏是一個例子:pymssql如何在查詢結果
( '999001', '4871C9DF-6E95-458B-B763-6BBBB6C75F5D',1 ,2,'EOI','Dropped',None,None,4,False,False,'Enbloc',False,False,False,False,None,None,None,None,None,None,None ,沒有,沒有,'投資',沒有,沒有,'JLL Deal','獨家授權','銷售諮詢',沒有,沒有,沒有,沒有,沒有,'Korea Standard Time',None,None,沒有,沒有,沒有,沒有,沒有,沒有,沒有,1,沒有,真的,'En-bloc',假的,假的,假的,假的,假的,假的,無,無,小數('0.05'),'100%',無,無,無,無,'Sqft','USD',十進制('120000000.00'),'USD $ 120.0M', Decima公司('120000000.00'),'USD $ 120.0M',無,無,無,無,無,無,無,無,十進制('120000000.00'),十進制('120000000.00'),十進制'120000000.00'),小數('120000000.00'),'未披露','Hubville Co Ltd'',令人興奮的投資機會 - 通往首爾的門戶',無,無,無,'令人興奮的投資機會 - The Gateway到'Seoul',None,None,datetime.datetime(2016,1,15,0,5,51,480000),datetime.datetime(2016,12,7,5,6,52,633000),1,None)
但我發現有像Decimal('120000000.00')
和datetime.datetime(2016, 1, 15, 0, 5, 51, 480000)
這樣的值。我只想獲取沒有Decimal()和datetime.datetime()的原始值。我怎樣才能實現這個?
這裏是我的代碼:
def extract_opportunities(sql):
cursor.execute(sql)
opportunities = cursor.fetchall()
attributes = get_attributes_of_table(cursor)
availability_id_idx = attributes.index("availabilityid")
opportunity_dict = dict()
for idx, val in enumerate(opportunities):
opportunity_key = val[availability_id_idx]
opportunity_value = dict(zip(attributes, val))
opportunity_dict[opportunity_key] = opportunity_value
該功能的目的是構建具有屬性和值對的JSON格式的文件,如:
{'Price': '120000000.00'}
,而不是
{'Price': Decimal('120000000.00')}
謝謝,這很有幫助! – Leo