是否可以使用assert_equal來比較對象?我不斷看到這樣的錯誤:學習Python的難題,例49:使用assert_equal來比較對象
AssertionError: <ex49.parser.Sentence object at 0x01F1BAF0> !=
<ex49.parser.Sentence object at 0x01F1BB10>
相關的代碼片段:
def test_parse_subject():
testsentence = "princess go east"
result = lexicon.scan(testsentence)
Sent = parse_sentence(result)
ResultSent = Sentence(('subject', 'princess'),
('verb', 'go'),
('object', 'east'))
print ResultSent.subject
print ResultSent.verb
print ResultSent.object
print Sent.subject
print Sent.verb
print Sent.object
assert_equal(Sent, ResultSent)
屏幕上的打印輸出表明對象具有相同的內容 - 但斷言錯誤出現。爲什麼是這樣?有什麼方法可以用assert_equal來覆蓋這個嗎?