In article <[EMAIL PROTECTED]>,
Ben Finney <[EMAIL PROTECTED]> wrote:
> Erik Max Francis <[EMAIL PROTECTED]> wrote:
> > Ben Finney wrote:
> > > If I want to implement a __repr__ that's reasonably "nice" to the
> > > programmer, what's the Right Way? Are there recipes I should look
> > > at?
> >
Ben Finney wrote:
> Well that just begs the question: what's a good way (or a Right Way,
> if that exists) to write a __str__ for a complex class?
Whatever is most useful for the programmer during debugging.
> An idempotent __repr__ output seem to be the ideal, but as you say,
> there are many
Erik Max Francis <[EMAIL PROTECTED]> wrote:
> Ben Finney wrote:
> > If I want to implement a __repr__ that's reasonably "nice" to the
> > programmer, what's the Right Way? Are there recipes I should look
> > at?
>
> I tend to use:
>
> def __repr__(self):
> if hasattr(self, '__str__'
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> In <[EMAIL PROTECTED]>, Ben Finney wrote:
>
> > class Human_Sex(str):
> > def __repr__(self):
> > repr_str = "%s(name=%s)" % (
> > self.__class__.__name__,
> > str.__repr__(self)
> >
In <[EMAIL PROTECTED]>, Ben Finney wrote:
> class Human_Sex(str):
> def __repr__(self):
> repr_str = "%s(name=%s)" % (
> self.__class__.__name__,
> str.__repr__(self)
> )
> return repr_str
I'm a bit surprised that `Hu
Ben Finney wrote:
> The builtin types have __repr__ attributes that return something nice,
> that looks like the syntax one would use to create that particular
> instance.
>
> The default __repr__ for custom classes show the fully-qualified class
> name, and the memory address of the instance.
>
Ben Finney <[EMAIL PROTECTED]> wrote:
> If I want to implement a __repr__ that's reasonably "nice" to the
> programmer, what's the Right Way? Are there recipes I should look
> at?
As a (carefully selected) example from the code I'm writing:
>>> import lib.attribute
>>> m = lib.attribute.
Howdy all,
The builtin types have __repr__ attributes that return something nice,
that looks like the syntax one would use to create that particular
instance.
The default __repr__ for custom classes show the fully-qualified class
name, and the memory address of the instance.
If I want to impleme