我在Python中有以下代码:
def buildXmlUpdate(dfrom, roomId, ldays):
start_date_sard.text = dfrom
roomId = str(roomId)
room_id_sard.text = roomId
ldays = {'avail': str(), 'price': str()}
availability_in_data.text = ldays['avail']
price_in_data.text = ldays['price']
for n in ldays:
print (dfrom, roomId, ldays)
现在正在运行
buildXmlUpdate ('21/12/2015', 1, [{'avail': 1, 'price': 100}, {'avail': 3, 'price': 120}])
我得到以下输出
('21/12/2015', '1', {'avail': '', 'price': ''})
('21/12/2015', '1', {'avail': '', 'price': ''})
换句话说:
('21/12/2015', '1', {'avail': 1, 'price': 100})
('21/12/2015', '1', {'avail': 3, 'price': 120})
如您所见,字典avail
和price
键设置为空字符串,但我想根据方法中的ldays
参数设置它们。
我做错了什么?
答案 0 :(得分:0)
解决:
def buildXmlUpdate(dfrom, roomId, ldays):
start_date_sard.text = dfrom
roomId = str(roomId)
room_id_sard.text = roomId
#ldays = {'avail': str(), 'price': str()}
#availability_in_data.text = ldays['avail']
#price_in_data.text = ldays['price']
for n in ldays:
print (dfrom, roomId, n)
#availability_in_data.text = get.ldays['avail']
#price_in_data.txt = get.ldays['price']
ldays[-1]['avail'] = str(ldays[-1]['avail'])
ldays[-1]['price'] =str(ldays[-1]['price'])
availability_in_data.text = ldays[-1]['avail']
price_in_data.text = ldays[-1]['price']
谢谢大家!