[Tutor] How o convert spaces into tabs??
vince spicer
vinces1979 at gmail.com
Tue Jun 2 20:34:27 CEST 2009
regex will do it
import re
line = re.sub(r"\s+", "\t", line)
print line
Vince
On Tue, Jun 2, 2009 at 11:42 AM, jyotsna guleria
<jyotsna.guleria at gmail.com>wrote:
>
> Hello every one,
>
> I am trying to parse a file:
>
> I want to convert all the spaces in between the characters to single tab.
>
> e.g: my file has contents like:
>
> 1G5 79011 1 0 2 0 0 0
> 0 0 0 0
> 5Ht-2 60459 1 1 0 0 0 0
> 0 0 0 0
>
>
> I want them to be separated by a single tab not with spaces..
>
> It should look like:
>
> 1G5 79011 1 0 2 0 0 0 0 0 0 0
> 5Ht-2 60459 1 1 0 0 0 0 0 0 0 0
>
> each separated by Tab...
>
> It is a text file containing such a data ..
>
>
> Thanks
> --
> Jyotsna Guleria
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090602/35fcb584/attachment.htm>
More information about the Tutor
mailing list