ユーザー定義オブジェクトを比較する必要がある Python (3.2) でプロジェクトを行っています。compareTo()
以下の例のように、クラスの自然な順序付けを指定するクラスでメソッドを定義する Java での OOP に慣れています。
public class Foo {
int a, b;
public Foo(int aa, int bb) {
a = aa;
b = bb;
}
public int compareTo(Foo that) {
// return a negative number if this < that
// return 0 if this == that
// return a positive number if this > that
if (this.a == that.a) return this.b - that.b;
else return this.a - that.a;
}
}
私はPythonのクラス/オブジェクトにかなり慣れていないので、クラスの自然な順序を定義する「pythonic」の方法は何ですか?