textwrap.dedent replaces tabs?

Tom Plunket tomas at fancy.org
Tue Dec 19 01:39:57 EST 2006


Frederic Rentsch wrote:

> > Well, there is that small problem that there are leading tabs that I
> > want stripped.  I guess I could manually replace all tabs with eight
> > spaces (as opposed to 'correct' tab stops), and then replace them when
> > done, but it's probably just as easy to write a non-destructive dedent.
>
> This should do the trick:
> 
>  >>> Dedent = re.compile ('^\s+')
>  >>> for line in lines: print Dedent.sub ('', line)

The fact that this doesn't do what dedent() does makes it not useful.
Stripping all leading spaces from text is as easy as calling lstrip() on
each line:

text = '\n'.join([line.lstrip() for line in text.split('\n')])

alas, that isn't what I am looking for, nor is that what
textwrap.dedent() is intended to do.

-tom!

-- 



More information about the Python-list mailing list