[Tutor] detab to delouse before de numbers go in (groan)
Magnus Lyckå
magnus@thinkware.se
Mon May 19 05:47:02 2003
At 19:36 2003-05-18 -0400, Kirk Bailey wrote:
>ok, files using taqbs confuse composition software. So we pull them out
>and insert spaces instead.
>
>def removetabs(string1):
> outstring=''
> for x in string1:
> if x=='\t':
> x=' '
> outstring=outstring+x
> return outstring
This won't do the right thing if there is a mix of tabs and
spaces in the code.
For Python, the following are all equivalent:
<space><space><space><space><space><space><space><space>a=5
<space><space><space><space><tab>a=5
<tab>a=5
<space><tab>a=5
Tab doesn't move a certain amount of positions forward, it
fills up to the next column with a position that is evenly
divisible by 8.
But you don't need any advanced code to fix that. Know thy library!
>>> help(str.expandtabs)
Help on method_descriptor:
expandtabs(...)
S.expandtabs([tabsize]) -> string
Return a copy of S where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
The simplest way to convert a file is to use the supplied script in
the python source distribution: Tools/scripts/untabify.py
It's in ActivePython, but I don't know if it's in other binary
distributions. It's certainly in CVS though.
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Tools/scripts/untabify.py
--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The shortest path from thought to working program