我有一個樣本代碼看起來像這樣,值(位置= 2,object.position = 3):奇怪python的比較行爲
new_position = position
old_position = object.position
logging.debug("1. new_position: %s, old_position: %s" % (new_position, old_position))
if old_position != new_position:
logging.debug("old position other than new position")
if new_position > old_position:
logging.debug("Why am I here ?")
現在調試:
DEBUG 1. new_position: 2, old_position: 3
DEBUG 2. old position other than new position
DEBUG Why am I here?
將'%s'說明符更改爲'%r',然後發佈輸出。 – Omnifarious 2010-10-30 18:24:35
順便說一句,你不應該使用'object'這個名字,因爲它指的是內置類型的'object',它可能會混淆你的程序 – 2010-10-30 18:28:11