print は、文字列や数値などを表示するものであり、通常インスタンスを表示することはできない。 表示するためには、クラス定義の際に __repr__ 関数を実装する必要がある。 class reprtest(object): def __init__(self, name, construction): self.name = name self.construction = construction def __repr__(self): return "<reprtest '%s' : '%s'>" % (self.name, self.construction) repr = reprtest("John Lennon", "The Beatles") print reprなお、__repl__関数を実装する場合、対象オブジェクトを再生成できるような情報を返すことが慣習となっている
