0
我在Python中有一個奇怪的問題。我有以下代碼:值不顯示打印
for cd in self.current_charging_demands:
print"EV{}".format(cd.id)
# Check the value of SOC.
for cd in self.current_charging_demands:
print"EV{}, Current SOC: {}, required power: {}, allocated power: {}, max power: {}\n".format(cd.id, round(cd.battery.current_soc, 2), cd.battery.power_to_charge, cd.battery.allocated_powers, cd.battery.max_power)
if round(cd.battery.current_soc, 2) >= cd.battery.desired_soc:
#print"EV{} - current SOC: {}".format(cd.id, cd.battery.current_soc)
result.append(cd)
db.delete_charging_demand(self.current_charging_demands, cd.id)
第一的是打印這些值:
EV1
EV2
EV5
EV4
第二個是打印這些:
EV1, Current SOC: 0.44, required power: 15.1, allocated power: 0.15638636639, max power: 3.3
EV2, Current SOC: 0.9, required power: 1.0, allocated power: 1.0, max power: 1.0
EV4, Current SOC: 0.92, required power: 6.5, allocated power: 3.3, max power: 3.3
正如你所看到的,一個值( EV5)在第二個失蹤,我真的不能解釋爲什麼。 for是在兩個循環之間沒有被修改的同一個對象上完成的。在這些功能的下一次調用,我得到以下值:
EV1
EV5
EV4
的第一個環和:
EV1, Current SOC: 0.44, required power: 15.0, allocated power: 0.15638636639, max power: 3.3
EV5, Current SOC: 0.35, required power: 23.7, allocated power: 0.0, max power: 3.3
EV4, Current SOC: 0.92, required power: 3.2, allocated power: 0.0, max power: 3.2
上正在發生的事情你知道嗎?
非常感謝。
謝謝,它現在可行! – Ecterion