File Parsing Question

Shankarjee Krishnamoorthi shankarjee at gmail.com
Wed Sep 12 18:28:08 EDT 2007


I would prefer to use something with seek. I am not able to use seek()
with "for line in inp". Use tell and seek does not seem to do anything
with the code. When I try to do

for line in inp.readlines():
    # Top of Loop
    if not condition in line:
            do_something
    else:
          for lines in inp.readlines():
              if not condition
                   do_something
              else:
                   break
                   pos = inp.tell()
   inp.seek(pos)   ---> This line has not effect in the program

Not sure if Iam missing something very basic. Also the previous line
needs to be used in the position I call # Top of Loop.

Thanks


On 9/12/07, Zentrader <zentraders at gmail.com> wrote:
> I'm assuming you know that python has a file.seek(), but you have to
> know the number of bytes you want to move from the beginning of the
> file or from the current location.  You could save the length of the
> previous record, and use file seek to backup and then move forward,
> but it is simpler to save the previous rec or use readlines() if the
> file will fit into a reasonable amount of memory.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list