eval(repr(x)) == x
Oren Tirosh
oren-py-l at hishome.net
Sun Jan 27 04:26:26 EST 2002
For many python builtins eval(repr(x)) == x. I find this property very
useful for debugging and writing tests. In some cases I write my own
classes so their repr is an expression that recreates their state.
For some python builtins this could be true, but isn't. Is there anyone
else who thinks it might be more consistent if this applied to more
builtins? I'm mostly talking about objects that have a __name__ attribute
like types, classes and functions.
The __repr__ function for these types could be something like this:
def __repr__(self):
return "%s.%s" % (self.__module__, self.__name__)
Oren
More information about the Python-list
mailing list