Rich __repr__



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 implement a __repr__ that's reasonably "nice" to the
programmer, what's the Right Way? Are there recipes I should look at?

--
\ "For certain people, after fifty, litigation takes the place of |
`\ sex." -- Gore Vidal |
_o__) |
Ben Finney
.



Relevant Pages

  • Re: C++ sucks for games
    ... > mistakes it is possible for a programmer to make (although of course memory ... > references and memory management is a bit of a red herring here. ... you would use smart pointers too. ...
    (comp.lang.lisp)
  • Re: Databases in Forth
    ... want without being forced to change syntax. ... You've just demonstrated the opposite-- a Forth programmer trying to ... apply a Forth mindset to C and coming up with a bizarre notion that C ... stack pointer but other per-context data. ...
    (comp.lang.forth)
  • Re: Databases in Forth
    ... want without being forced to change syntax. ... You've just demonstrated the opposite-- a Forth programmer trying to ... apply a Forth mindset to C and coming up with a bizarre notion that C ... stack pointer but other per-context data. ...
    (comp.lang.forth)
  • Re: ASTs in assembler
    ... Absolutely I don't mean optimizing what has written by the programmer. ... idea of the assembler being able to have a "big picture" of the source. ... Because of the amount of memory modern machines have, ... Why not read macro bodies from macro symbol table? ...
    (alt.lang.asm)
  • Re: RPN maps to basic mathematic expressions nicely
    ... A novice C programmer may have problems understanding this, but it's actually quite idiomatic for embedded systems programmers. ... void delay ... A C programmer could also do this at compile time with some macros, but probably more common would be to deal with this with a run-time interpreter for a "language" of dits and dahs: ... If your primary language is C, you're likely looking at the Forth code and thinking that the SWAP and verbose syntax for ORing-in a 0x01 says you're dealing with a language one step above assembler. ...
    (comp.lang.forth)