Newby Question for reading a file

alex23 wuwei23 at
Thu Feb 19 19:44:18 EST 2009

On Feb 20, 5:38 am, Peter Otten <__pete... at> wrote:
> Yes you can get portions of the line by slicing:
> for line in open("infile"):
>     if line[8:18] != line[18:28]:
>             print line,

You can also name the slices, which makes the code more clear (IMO):

endda = slice(8,18)
begda = slice(18,28)
for line in open("infile"):
    if line[endda] != line[begda]:
            print line,

> Or you can use the struct module:

But this is the approach I'd take.

More information about the Python-list mailing list