eval(repr(x)) == x
aleax at aleax.it
Sun Jan 27 22:11:46 CET 2002
Oren Tirosh wrote:
> Functions, classes and types are first-class objects in Python. I tend to
> use them as such: pass them around, use them as members of containers,
> dictionary keys, etc.
Me too -- how else would one use Python?
> It bothers me that for the repr function they are
> second-class citizens. Their repr is some kind of 'tourist information'
> instead of valid expressions like the repr of numbers, sequences,
> dictionaries, etc.
> I guess your programming style is different so it doesn't bother you.
The reason it doesn't bother me must be different. I see repr's role as
first and foremost one of helping me to identify objects -- of course
ones to which Python syntax devotes literal forms are going to be
"identified" in a different style than types, instances, classes, functions,
modules, bound methods, unbound methods, stack frames, and so on,
which do not have "literal" (aka "display") forms in Python syntax.
I also often enough use _nested_ def and class statements, that the
form you've proposed for such objects as functions would leave me in
a total quandary (wrt repr only of course), unable to tell if two (e.g.)
classes or functions that are named the same ARE equal or not. The
current form makes this easy, and I would never want to lose that. Maybe
there's a stylistic difference there, and you don't tend to use closures and
other nested forms?
More information about the Python-list