可以簡化這個嗎?也許把兩者結合起來?告訴我DRY的方法: - \在Python中,我可以在一個條件中處理兩個變量嗎?
o = old_last_result
if o == 7:
old_last_result_msg = result_7
elif o == 12:
old_last_result_msg = result_12
elif o == 23:
old_last_result_msg = result_23
elif o == 24:
old_last_result_msg = result_24
elif o == 103:
old_last_result_msg = result_103
elif o == 1000:
old_last_result_msg = result_1000
else:
old_last_result_msg = "Error code: #%s" % old_last_result
n = new_last_result
if n == 7:
new_last_result_msg = result_7
elif n == 12:
new_last_result_msg = result_12
elif n == 23:
new_last_result_msg = result_23
elif n == 24:
new_last_result_msg = result_24
elif n == 103:
new_last_result_msg = result_103
elif n == 1000:
new_last_result_msg = result_1000
else:
new_last_result_msg = "Error code: #%s" % new_last_result
甜。剛剛擡起頭.get()http://docs.python.org/library/stdtypes.html#dict.get – Flowpoke 2011-01-29 00:42:37