textwrap.dedent replaces tabs?

Frederic Rentsch anthra.norell at vtxmail.ch
Fri Dec 29 07:49:20 EST 2006


Tom Plunket wrote:
> Frederic Rentsch wrote:
>
>   
>> Your rules seem incomplete.
>>     
>
> Not my rules, the stated documentation for dedent.  "My" understanding
> of them may not be equivalent to yours, however.
It's not about understanding, It's about the objective. Let us consider 
the difference between passing a driving test and riding a bicycle in 
city traffic. The objective of passing the test is getting the license 
and the means is knowing the rules. The objective of riding the bicycle 
is surviving and the means is anticipating all possible breaches of 
rules on he part of motorists.

> What if common tabs remain after stripping common white space?
> What if we just go with, "[r]emove any whitespace than can be uniformly
> removed from the left of every line in `text`." ?
>   
>> Does this never happen? Or can we hope it doesn't happen?
>>     
>
> "Hope" has no place in programming software that is to be used by
> others.
>
>   
That's exactly what I am saying. That's exactly why it may be a good 
idea to provide preventive measures for rules being breached be those 
others over whom we have no control.

>> To err on the side of caution I complete your rules and this is my 
>> (tested) attempt at expressing them pythonically.
>>     
>
> Inasmuch as "my" rules have been expressed via tests, the provided code
> fails four of the five tests provided.
>
>   
toms_test_data = (
   ( "\n   Hello\n      World",   # Do this
     "\nHello\n   World", ),      # Expect this
   ( "\n\tHello\n\t   World",
     "\nHello\n   World", ),
   ( "\t\tHello\n\tWorld",
     "\tHello\nWorld", ),
   ( "Hello\n\tWorld",
     "Hello\n\tWorld", ),
   ( "  \t Hello\n   \tWorld",
     "\t Hello\n \tWorld", ),
)
 >>> for dedent_this, expect_this in toms_test_data:
    done = '\n'.join (dedent (dedent_this.splitlines ()))
    if done == expect_this: print 'BRAVO!!!'
    else: print 'SHAME ON YOU!!!'
   
BRAVO!!!
BRAVO!!!
BRAVO!!!
BRAVO!!!
BRAVO!!!

You seem to have plugged my function into your tester. I wasn't 
concerned about your testing interface but about the dedentation.
>> (I admit it does look awfully sevety-ish. Just a vulgar little 
>> function.)
>>     
>
> Seventys-ish is as much a statement about the lack of statement about
> how you actually tested it as it is that an implementation was made
> apparently without understanding of the requirements.
>
>
> -tom!
>
>   
Best regards

Frederic





More information about the Python-list mailing list