Preserving program structure

Dave Kuhlman dkuhlman at rexx.com
Sat Dec 15 16:57:53 EST 2001


Chris Barker <chrishbarker at attbi.com> wrote:
> 
> David Dawkins wrote:
>> So I'm using IDLE, and Alt-F5 tells me I have a problem with
>> indentation.
>> 
>> It seems I had (inadvertently) mixed tab and space characters.
>> No amount of "tabbifying" and "untabbifying" resolved the issue,
>> so I had to shift *everything* to the left-margin, and re-create
>> the indentation with a consistent scheme (8 space hard tabs).
> 
> I'm confused. How is it that "untabbifying" didn't resolve it? While you
> may have had a couple of indentations messed up, I would think that
> would be a whole lot easier to fix than re-indenting the entire code!

A possible explanation -- Suppose that the file you are trying to
fix (1) mixes tabs and spaces and (2) suppose the file assumes that
tabs are expanded by the Python interpreter to 8 spaces and (3)
suppose that when you untabify, you expand them to 4 spaces.

Lesson to be learned -- before untabifying, analyse the file to
determine how many spaces you should replace each tab with.

> 
> By the way, I don't know about IDLE, but PythonWin (and other editors)
> has a mode that allows you to see tabs and spaces, so you can easily go
> in a clean out the ones that you don't want.

It will also help to set the tab size in your editor, then check
the visual appearance of blocks of code so that indented control
structures appear correct.  Then, that tab setting is likely to be
the number of spaces to replace a tab with when you untabify.

By the way, when I do my untabifying, I use the UNIX expand and
unexpand commands.  Are there better tools for this?  Is
untabify.py any safer?

> 
> 
> -Chris
> 

-- 
Dave Kuhlman
dkuhlman at rexx.com


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



More information about the Python-list mailing list