<div class="gmail_quote">On Tue, Jun 2, 2009 at 12:42 PM, jyotsna guleria <span dir="ltr">&lt;<a href="mailto:jyotsna.guleria@gmail.com">jyotsna.guleria@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br clear="all">Hello every one,<br><br>I am trying to parse a file:<br><br>I want to convert all the spaces in between the characters to single tab.<br><br>e.g: my file has contents like:<br><br>1G5            79011      1        0      2       0      0        0       0       0       0        0<br>


5Ht-2          60459      1        1      0       0      0        0       0       0       0        0<br><br><br>I want them to be separated by a single tab not with spaces..<br><br>It should look like:<br><br>1G5    79011    1    0    2    0    0    0    0    0    0    0<br>


5Ht-2    60459    1    1    0    0    0    0    0    0    0    0<br><br>each separated by Tab...<br><br>It is a text file containing such a data ..<br></blockquote></div><br>Easiest way I know of goes something like this:<br>

<br>for line in myfile:<br>   newline = &#39;\t&#39;.join(line.split())<br><br>Consider:<br><br>In [16]: x = &#39;the quick brown    fox   ate   some   spam and     eggs&#39;<br><br>In [17]: x.split()<br>Out[17]: [&#39;the&#39;, &#39;quick&#39;, &#39;brown&#39;, &#39;fox&#39;, &#39;ate&#39;, &#39;some&#39;, &#39;spam&#39;, &#39;and&#39;, &#39;eggs&#39;]<br>

<br>In [18]: &#39;\t&#39;.join(x.split())<br>Out[18]: &#39;the\tquick\tbrown\tfox\tate\tsome\tspam\tand\teggs&#39;<br><br>In [19]: print &#39;\t&#39;.join(x.split())<br>the     quick   brown   fox     ate     some    spam    and     eggs<br>

<br><br>HTH,<br>Wayne<br>