File Parsing Question

Shankarjee Krishnamoorthi shankarjee at gmail.com
Wed Sep 12 17:00:52 EDT 2007


Hi,
   I am new to Python. I am trying to do the following

inp = open(my_file,'r')

for line in inp:
  # Perform some operations with line
   if condition something:
         # Start re reading for that position again
         for line in inp:
              if some other condition
                     break
         # I need to go back one line and use that line value.
         # I need to perform the operations which are listed in the
top with this line
         #  value. I cannot push that operation here
         # I cannot do this with seek or tell.

In Perl this is what I have
while (<inp> ){
           # my_operations
           next if /pattern/
           while (<inp>) {
                   operations again
                   last if /pattern2/
           }
           seek(inp,(-1-length),1)
}

This works perfectly in Perl. Can I do the same in Python.

Thanks
Jee



More information about the Python-list mailing list