Line indexing in Python

Lie Ryan lie.1296 at gmail.com
Fri Dec 18 11:54:10 EST 2009


On 12/19/2009 3:27 AM, seafoid wrote:
>
> Thanks for that Richard and Steve.
>
> I have another question.

What's the question?

> fname = raw_input('Please enter the name of the file: ')
>
> # create file objects
>
> blah = open(fname, 'r')
> a = open('rubbish', 'w')
>
> for line in blah:
>      if line.startswith("0"):
>          a.write(line)
>      elif line.endswith("0"):
>          lists_a = line.strip().split()
>          print lists_a

The following block is a dead code; the block will never be executed 
since if line.startswith("0") is true, the control will fall to the 
a.write(line) block and this block is skipped.
>      elif line.startswith("0"):
>          lists_b = line.strip().split()
>          print lists_b
>
> Essentially, I wish to take input from a file and based on the location of
> zero, assign lines to lists.
>
> Any suggestions?
>
> Seafoid.
>




More information about the Python-list mailing list