我有一些代碼,我想通過實例或類交替傳遞。我將在該代碼中執行的所有操作都是調用我期望類和實例都具有的方法(以下示例中的方法爲go())。 不幸的是,我無法用常規方法的相同名稱創建classmethod ...請參閱下面的示例。我最初預計第二次電話會產生一個a而不是一個b。 有關如何實現此目的的任何建議? Type "help", "copyright", "credits" or "license"
也許我的設計完全沒有重擊,但如果我有2派生類對象是可比較的,但類D1基本上總是> D2類。 (說比較常春藤橋到286)。我如何實施D1類比較來反映不使用isinstance(D2)? 我看到這一點: Comparing two objects 和 If duck-typing in Python, should you test isinstance? 我可以添加一個「類型」屬性,然後比較類型,但
在the manual是說: in general, __lt__() and __eq__() are sufficient, if you want the conventional meanings of the comparison operators 但我看到的錯誤: > assert 2 < three
E TypeError: unorderable types: int()