__str__ vs. __repr__

Emile van Sebille emile at fenx.com
Wed Nov 10 05:15:15 CET 1999


Neel,

Ah, but you didn't disagree!  ;-)  Testing certainly is useful, and
for the tester it *is* work, but that's code that is not in production,
which is when the code *is* working.

I quote now from Paul Foley <mycroft at actrix.gen.nz>, who e-mailed me
a sample interactive session using a function describe():

>
> You mean something like this:
>
> >>> x="Testing"
> >>> describe(x)
> A string containing 7 characters.
> >>> import sys
> >>> describe(sys)
> The `sys' module.
> The module has no documentation string.
>
> It exports the following functions: ['setcheckinterval', 'exc_info',
'exit', 'setprofile', 'settrace', 'getrefcount']
>
> It exports the following variables: ['platform', 'stderr', 'version',
'builtin_module_names', 'modules', 'stdin', 'exec_prefix', 'copyright',
'executable', 'exc_type', 'ps1', 'ps2', 'path', 'maxint', 'prefix',
'argv', 'stdout']
> >>> describe(sys.exit)
> The built-in function `exit'.
> >>> describe(sys.stdin)
> A file open for reading on `<stdin>' (a TTY device)
> The underlying file descriptor is 0.
> The current file position is 0.

This is what I had in mind.  To further enhance the utility of
interactive
mode by providing more information to the programmer.  Certainly __str__
and __repr__ are The Wrong Way (tm) to do this, and describe() much
better.
Any and everything more that describe() could do should be added to it.
Add
-v, -vv, -vvv options as appropriate.  Show the source entry line.  Hey,
show
the whole routine. ;-0  (Let's see... get line number from bytecode,
read
source for line, note indent, display until match indent... is that it?)

is-what-we-do-work-ly yr's

--

Emile van Sebille
emile at fenx.com
-------------------


Neel Krishnaswami <neelk at brick.cswv.com> wrote in message
news:slrn82hhtv.ppi.neelk at brick.cswv.com...
> Emile van Sebille <emile at fenx.com> wrote:
> >
> >It seems to me that issues arise when using the interactive
interpreter.
> >I suspect that little useful work is done in this mode, and is used
> >predominately for quick testing while creating python programs.
>
> I'd like to politely disagree . Combined with Tim Peters and Barry
> Warsaw's emacs py-mode, Python's interactive mode is the single most
> useful feature of the language for me. With it, I can test each and
> every method, loop, and statement as I code. This does wonders for my
> understanding of my code. And not incidentally, reliability goes way
> up as well.
>
> I learned Perl before Python, but my Python skill surpassed my Perl
> skill after a much smaller time investment. I lay this pretty much
> wholely at the feet of the interactive interpreter -- I could find out
> the answers to puzzles without a tedious edit-save-run cycle.
>
>
> Neel
>
> --
> http://www.python.org/mailman/listinfo/python-list
>
>






More information about the Python-list mailing list