textwrap.dedent replaces tabs?

Tom Plunket tomas at fancy.org
Mon Dec 25 20:29:19 EST 2006


Frederic Rentsch wrote:

> It this works, good for you. I can't say I understand your objective. 
> (You dedent common leading tabs, except if preceded by common leading 
> spaces (?)).

I dedent common leading whitespace, and tabs aren't equivalent to
spaces.

E.g. if some text is indented exclusively with tabs, then the leading
tabs are stripped appropriately.  If some other text is indented with
common leading spaces, those are stripped appropriately.  If the text to
be stripped has some lines starting with spaces and others starting with
tabs, there are no /common/ leading whitespace characters, and thus
nothing is stripped.

> Neither do I understand the existence of indentations made up of tabs 
> mixed with spaces, but that is another topic.

At one point it was a fairly common cry in the How To Indent Python
discussions.  Maybe that cry has faded.

>      I have been wasting a lot of time with things of this nature coding 
> away before forming a clear conception in my mind of what my code was 
> supposed to accomplish. Sounds stupid.

Doesn't sound stupid, but there are in fact some fairly straight forward
methods that can be put in place to alleviate that problem.

> The encounter with the devil in the details can be put off but not 
> avoided. Best to get it over with from the start and write an exhaustive 
> formal description of the problem. Follows an exhaustive formal 
> description of the rules for its solution.

Good lord, that's an amazingly 1970s way to look at programming!  Modern
software engineering practices have in some ways made these problems go
away.

> In other words, coding should be the translation of a logical system 
> into a language a machine understands. It should not be the construction 
> of the logical system. This, anyway, is the conclusion I have arrived 
> at, to my advantage I believe.

To each their own, eh?  I've been doing this a long time and have found
that it is by far superior (for me) to refine the logical system as it
is being implemented, as long as the business rules are encoded in such
a way as to disallow the programmer from straying beyond them.

My unit tests are far from exhaustive, but with code this simple it
didn't seem terribly important since I was doing it more as a proof of
concept, proving that I could do this sort of thing in not-many-more-
lines-than-the-original-code-that-does-not-operate-to-its-published-
specification.


-tom!

-- 



More information about the Python-list mailing list