add an indent to a stream
Phillip J. Eby
pje at telecommunity.com
Wed Mar 12 09:03:22 EST 2003
Manuel M Garcia <mail at manuelmgarcia.com> wrote in message news:<ld0o6vkta9u7v9un1d1otuvj7nste92ni2 at 4ax.com>...
> I often need to add an indent to a stream, usually so the output of
> pprint or traceback is indented so I can tell debugging output from my
> program's actual output.
>
> Below is a class to help do this. I think I got the details right.
> The 'print' statement, when used with commas, is more complicated than
> I thought.
>
If you need a generally indentable/outdentable stream, you might try
the class documented here:
http://peak.telecommunity.com/doc/src/peak/util/IndentedStream/IndentedStream.html
The code is at:
http://cvs.eby-sarna.com/PEAK/src/peak/util/IndentedStream.py?rev=HEAD&content-type=text/vnd.viewcvs-markup
IndentedStream is intended for generating Python or XML output, so it
manages a stack of indent levels which can be pushed and popped. It
also does its indentation lazily, so that if you output a newline and
then change the indent level, it won't have indented the new line yet
unless something was written to the new line.
More information about the Python-list
mailing list