Something more beautiful than <__main__.MyClass instance at 0x1624710>

This is my class (as simple as it can be):

class MyClass():
    def __init__(self, id): = id

    def __str__(self):
        return "MyClass #%d" %

When I print an object of MyClass, I get this beautiful string: MyClass #id. But when I just "show it" in the interpreter, I still get this nasty <__main__...>. Is there a way to change this behaviour?

>>> c = MyClass(5)
>>> print c
MyClass #5
>>> c
<__main__.MyClass instance at 0x1624710>


def __repr__(self):
    return 'MyClass #%d' % (,)

Need Your Help

ensure that PDO fetch method result “false” is a error or empty result

php mysql pdo

How can I recognize a fetch error or empty result from a execute error with php PDO mysql driver?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.