[Python-3000] Changing default __repr__ of type

Armin Ronacher armin.ronacher at active-4.com
Wed Jan 10 20:45:54 CET 2007


Hoi,

> gmane workaround

What drives me nuts personally is the default __repr__ of classes. (type
instances and not class instances).

Currently it looks like this::

    >>> Foo
    <class '__main__.Foo'>
    >>> mymodule.Foo
    <class 'mymodule.Foo'>

IMHO a better way is this one:

    >>> Foo
    Foo
    >>> mymodule.Foo
    mymodule.Foo

Because only classes and singletons (like True/False/None(/Ellipsis?)) have a
similar repr that's not such a big problem.

Especially for datetime this will be much more consistent then:

    >>> datetime.datetime.now()
    datetime.datetime(2007, 1, 10, 20, 43, 7, 52890)
    >>> datetime.datetime
    datetime.datetime

The advantages:

-   Smaller Output when working with the CLI
-   evalable (okay, that's not the best argument)
-   consistent (see the datetime example)

Regards,
Armin



More information about the Python-3000 mailing list