On Dec 12, 2007 6:34 PM, Darren Dale <[EMAIL PROTECTED]> wrote:
>
> On Wednesday 12 December 2007 7:58:10 pm Gael Varoquaux wrote:
> > Hi,
> >
> > I definetely don't like the fact that .__repr__() and repr() are used all
> > over TConfig for eg storing to file.
> >
> > First of all I would like to modify __repr__ for a TConfig class to give
> > a more synthetic view.
> >
> > I propose to change the current ".__repr__()" method to ".tostring()" and
> > to implement a more readable ".__repr__()".
> >
> > Are the different people interested in these issues OK with that? If yes,
> > where is the authoritative repo for TConfig? Which SVN should I start
> > hacking?
>
> I consider the authoritative TConfig to be the one in Ipython1.sandbox, but it
> doesnt matter in practice because I keep the two in sync.
>
> I do want to be able to save the verbose information to a file, since we want
> to be able to generate a commented file that people can use to learn how to
> make modifications. If that doesnt change, I don't have an objection to
> making __repr__ terse.

On second thought though: __str__ is the one meant for 'human
consumption', while __repr__ is deliberately meant to be much more
machine-like. Basically the idea is that, whenever possible, one can
do

x == eval(repr(x))

That is true for many of the builtin data types of the language.

Quoting http://docs.python.org/ref/customization.html#l2h-179 :

__repr__(       self)
    Called by the repr() built-in function and by string conversions
(reverse quotes) to compute the ``official'' string representation of
an object. If at all possible, this should look like a valid Python
expression that could be used to recreate an object with the same
value (given an appropriate environment). If this is not possible, a
string of the form "<...some useful description...>" should be
returned. The return value must be a string object. If a class defines
__repr__() but not __str__(), then __repr__() is also used when an
``informal'' string representation of instances of that class is
required.

    This is typically used for debugging, so it is important that the
representation is information-rich and unambiguous.

So Gael, would you be OK with a terser str() and leaving repr to honor
this python convention?

Cheers,

f

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to