Re: Re: column selection

mannu jha mannu_0523 at rediffmail.com
Fri May 7 10:24:56 EDT 2010



On Fri, 07 May 2010 18:58:59 +0530  wrote
>mannu jha wrote:

> On Thu, 06 May 2010 18:54:59 +0530 wrote

>  

>> mannu jha wrote:

>>   

>

>  

>> I tried with this:

>>   

>

>  

>

>  

>> for line in open('1.txt'):

>>   

>

>  

>>  columns = line.split()

>>   

>

>  

>>  print columns[0], columns[1]

>>   

>

>  

>>  if not line: continue

>>   

>

>  

>

>  

>> but it is showing error:

>>   

>

>  

>

>  

>> nmruser at caf:~> python split.py

>>   

>

>  

>> 24 ALA

>>   

>

>  

>> Traceback (most recent call last):

>>   

>

>  

>> File "split.py", line 3, in 

>>   

>

>  

>>  print columns[0], columns[1]

>>   

>

>  

>> IndexError: list index out of range

>>   

>

>  

>> nmruser at caf:~>

>>   

>

>  

>

>  

>> Thanks,

>>   

>

>  

>

>  

>> On Thu, 06 May 2010 15:44:07 +0530 wrote

>>   

>

>  

>> 

>>   

>

>  

>

>  

>

>  

>> If your files have two blank lines between each useful line, you have to 

>>   

>

>  

>

>  

>> do something to avoid trying to print those items for the blank lines. 

>>   

>

>  

>

>  

>> Depending how sure you are about your formatting, you could either do a

>>   

>

>  

>

>  

>> if not line: continue

>>   

>

>  

>

>  

>> or a

>>   

>

>  

>

>  

>> if columns < 3: continue

>>   

>

>  

>

>  

>

>  

>> DaveA

>>   

>

>

> with this 

>

> for line in open('8.txt'):

>    columns = line.split()

>    if columns python split.py

> 24 ALA

> Traceback (most recent call last):

>  File "split.py", line 4, in 

>   print columns[0], columns[1]

> IndexError: list index out of range

> nmruser at caf:~>

>

>

>  

>

>  

>

>  

>> 

>>   

>

> (Don't top-post. It makes the message very confusing to someone else 

>

> trying to follow it. Also, enable your mail program's quoting feature 

>

> -- currently it's not adding the marks at the beginning of each line you 

>

> quote.)

>

>

>

> If you're going to skip over blank lines, it'd be good to do it before 

>

> trying to print from it. Move the test up by a line.

>

>

>

> DaveA

>

>

>  

You forgot to include the list in your reply. Use reply-all, it's much 

easier.



No clue what that "if columns..." line is supposed to be. It should get 

a parse error.





DaveA


Thankyou very much sir........Thanks a lot.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100507/31364890/attachment-0001.html>


More information about the Python-list mailing list