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__関数を実装する場合、対象オブジェクトを再生成できるような情報を返すことが慣習となっている
![Python でインスタンス情報を print する | 僕と僕のサル以外、みんな何かを隠してる](https://cdn-ak-scissors.b.st-hatena.com/image/square/54eff32cbec67087a89d7c297b7df8ca5afe5c62/height=288;version=1;width=512/https%3A%2F%2Fimage.excite.co.jp%2Fjp%2FappleIcon%2Fapp%2Fblog%2Fapple-touch-icon.png)