Re: Rich __repr__

2005-11-02 Thread Donn Cave
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? > >

Re: Rich __repr__

2005-11-02 Thread Erik Max Francis
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

Re: Rich __repr__

2005-11-01 Thread Ben Finney
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__'

Re: Rich __repr__

2005-11-01 Thread Ben Finney
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) > >

Re: Rich __repr__

2005-11-01 Thread Marc 'BlackJack' Rintsch
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

Re: Rich __repr__

2005-10-31 Thread Erik Max Francis
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. >

Re: Rich __repr__

2005-10-30 Thread Ben Finney
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.

Rich __repr__

2005-10-30 Thread Ben Finney
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