space/tab conversion utility?

Brian van den Broek bvande at po-box.mcgill.ca
Wed Jul 28 19:36:43 EDT 2004


Grant Edwards said unto the world upon 28/07/2004 19:15:
> In article <mailman.898.1091055734.5135.python-list at python.org>, Brian van den Broek wrote:
> 
> 
>>>"unexpand" will do dumb conversion, but what's required is
>>>something that understands Python block syntax.  Something
>>>similar to C's "indent" program.
>>
>>OK, sorry. I'm still pretty new to Python and programming in general. But 
>>I would have thought that the recipe I pointed to could be used as the 
>>basis of a script that would uniformly replace all leading tabs with a set 
>>number of spaces, thus preserving relative indents. (On the assumption 
>>that the code being transformed is all tabs.)
> 
> 
> 1) The conversion I need to do is the other direction spaces->tabs.

Doh! :-[

> 2) Simply converting all leading spaces to the right number of
>    tabs (unexpand knows how to do that) isn't correct.  Only
>    the spaces that are block-indent spaces should be converted.

<Helpful explanation snipped>

>>If there's a subtlety that is blowing past me in my
>>newbieness, enlightenment would be appreciated. On the other
>>hand, if you'd like to see the code, I'd be happy to share.
> 
> 
> The problem is that sometimes lines contain leading spaces that
> shouldn't be converted to tabs.

Hi Grant,

thanks for the explanation. Since you probably have better things to do 
than play "spot the newbie's confusion" and I am fresh out of feet to 
stick in my mouth, let's leave it there ;-)

Best,

Brian vdB





More information about the Python-list mailing list