[Python-Dev] Traceback style
Guido van Rossum
guido@python.org
Tue, 02 May 2000 13:22:02 -0400
> On 02 May 2000, Ka-Ping Yee said:
> > I propose the following stylistic changes to traceback
> > printing:
> >
> > 1. If there is no function name for a given level
> > in the traceback, just omit the ", in ?" at the
> > end of the line.
Greg Ward expresses my sentiments:
> +0 on this: it doesn't really add anything, but it does neaten things
> up.
>
> > 2. If a given level of the traceback is in a method,
> > instead of just printing the method name, print
> > the class and the method name.
>
> +1 here too: this definitely adds utility.
>
> > 3. Instead of beginning each line with:
> >
> > File "foo.py", line 5
> >
> > print the line first and drop the quotes:
> >
> > Line 5 of foo.py
>
> -0: adds nothing, cleans nothing up, and just generally breaks things
> for no good reason.
>
> > In the common interactive case that the file
> > is a typed-in string, the current printout is
> >
> > File "<stdin>", line 1
> >
> > and the following is easier to read in my opinion:
> >
> > Line 1 of <stdin>
>
> OK, that's a good reason. Maybe you could special-case the "<stdin>"
> case? How about
>
> <stdin>, line 1
>
> ?
I'd special-case any filename that starts with < and ends with > --
those are all made-up names like <string> or <stdin>. You can display
them however you like, perhaps
In "<string>", line 3
For regular files I'd leave the formatting alone -- there are tools
out there that parse these. (E.g. Emacs' Python mode jumps to the
line with the error if you run a file and it begets an exception.)
--Guido van Rossum (home page: http://www.python.org/~guido/)