I am new to Python (2.6), and have a situation where I need to un-read a line I just read from a file. Here's basically what I am doing.
  for line in file:
     print line
     file.seek(-len(line),1)
     zz = file.readline()
     print zz
However I notice that "zz" and "line" are not the same. Where am I going wrong?
Thanks.
I don't think for line in file: and seek make a good combination. Try something like this:
while True:
    line = file.readline()
    print line
    file.seek(-len(line),1)
    zz = file.readline()
    print zz
    # Make sure this loop ends somehow
                        You simply cannot mix iterators and seek() this way. You should pick one method and stick to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With