<br />
I tried with this:<br />
<br />
for line in open('1.txt'):<br />
       columns = line.split()<br />
       print columns[0], columns[1]<br />
       if not line: continue<br />
<br />
but it is showing error:<br />
<br />
nmruser@caf:~> python split.py<br />
24 ALA<br />
Traceback (most recent call last):<br />
  File "split.py", line 3, in <module><br />
    print columns[0], columns[1]<br />
IndexError: list index out of range<br />
nmruser@caf:~><br />
<br />
Thanks,<br />
<br />
On Thu, 06 May 2010 15:44:07 +0530  wrote<br />
>mannu jha wrote:<br />
<br />
> Hi,<br />
<br />
><br />
<br />
> I have few files like this:<br />
<br />
><br />
<br />
> 24 ALA helix (helix_alpha, helix2)<br />
<br />
><br />
<br />
><br />
<br />
> 27 ALA helix (helix_alpha, helix2)<br />
<br />
><br />
<br />
><br />
<br />
> 51 ALA helix (helix_alpha, helix4)<br />
<br />
><br />
<br />
><br />
<br />
> 58 ALA helix (helix_alpha, helix5)<br />
<br />
><br />
<br />
><br />
<br />
> 63 ALA helix (helix_alpha, helix5)<br />
<br />
><br />
<br />
> now with this program:<br />
<br />
><br />
<br />
> for line in open('1.txt'):<br />
<br />
>    columns = line.split()<br />
<br />
>    print columns[0], columns[2] <br />
<br />
><br />
<br />
> I am trying to print only 1st and third column but it showing error like:<br />
<br />
> mruser@caf:~> python split.py<br />
<br />
> 24 helix<br />
<br />
> Traceback (most recent call last):<br />
<br />
>  File "split.py", line 3, in <br />
<br />
>   print columns[0], columns[2]<br />
<br />
> IndexError: list index out of range<br />
<br />
> nmruser@caf:~><br />
<br />
> how to rectify it.<br />
<br />
><br />
<br />
> Thanks,<br />
<br />
><br />
<br />
>  <br />
<br />
If your files have two blank lines between each useful line, you have to <br />
<br />
do something to avoid trying to print those items for the blank lines. <br />
<br />
Depending how sure you are about your formatting, you could either do a<br />
<br />
  if not line: continue<br />
<br />
<br />
<br />
or a<br />
<br />
   if columns < 3: continue<br />
<br />
<br />
<br />
DaveA<br />
<br />
<br />
<br />