space/tab conversion utility?
Brian van den Broek
bvande at po-box.mcgill.ca
Wed Jul 28 19:01:42 EDT 2004
Grant Edwards said unto the world upon 28/07/2004 18:12:
> On 2004-07-28, Brian van den Broek <bvande at po-box.mcgill.ca> wrote:
>
>>Grant Edwards said unto the world upon 28/07/2004 17:49:
>>
>>
>>>Is there any utility to convert Python sources from space-based
>>>block indentation to tab-based?
>>>
>>>You can use "expand" convert from tabs->spaces, but "unexpand"
>>>isn't bright enough to do the reverse.
>>>
>>
>>Hi,
>>
>><http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65226>
>
>
> I don't see how that's useful.
>
>
>>There are a couple of other tab/space recipes on the site, too.
>
>
> "unexpand" will do dumb conversion, but what's required is
> something that understands Python block syntax. Something
> similar to C's "indent" program.
>
Hi,
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.)
But getting your response made me read the recipe more carefully, and now
I think I see why you doubt its usefulness for your task.
Still, the approach of replacing only leading tabs seems to me like it
would work. I did up a script and from my testing it appears to preserve
block structure. But I hesitate to post code; one gaff a day is enough ;-)
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.
Anyway, sorry if I wasted your time.
Best,
Brian vdB
More information about the Python-list
mailing list