Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'lines,': 0.07; 'subject:file': 0.07; 'subject:two': 0.07; 'iterate': 0.09; 'pointers': 0.09; '(say': 0.16; '20)': 0.16; 'file))': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'loop.': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'basically': 0.19; 'possible,': 0.19; 'help.': 0.21; 'python?': 0.22; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'message- id:@mail.gmail.com': 0.30; 'lines': 0.31; 'sep': 0.31; 'file': 0.32; 'this.': 0.32; 'another': 0.32; 'subject:with': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'words,': 0.36; 'next': 0.36; 'hi,': 0.36; 'should': 0.36; 'so,': 0.37; 'two': 0.37; 'starting': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'till': 0.61; 'back': 0.62; 'different.': 0.84; 'off,': 0.84; 'subject:over': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=o1HIiL3d3Mnn/EXIJQFVhEmlmt+/n80y6I0/AulcIHM=; b=m0BVrhuPKYWYyTEPMOL39UglJ2PNGXtbUELG4dR6x4fVS99WmCzxsfOCPyr2CBRVVm p/L4wn9nl9g8HByqOAVtPfOSDWtqoqXClIPOlV0IqWyJIAHkc3uVQLKnvglkBjpGR3ep WOrgaNAW0HfLm5gOj3O2y31DBH6zDAIL8GBB1N/Lcw8iwDZHVtS9pjA71Fr+xm/ScF17 l3kXx0zYucVYYXXpVw73+qf/FmfXHz8yydfy81f9sBJvcxaGdM6GSIQCyzfVlPBI/bVI 6pFx3FisWIUz3rdZ3Ptytsu7G1pBPndbLYv8Y2HWar6d8dYsRAXEfsp5Devj6eY1oymR 0P9g== MIME-Version: 1.0 X-Received: by 10.52.64.143 with SMTP id o15mr31583190vds.16.1379503311592; Wed, 18 Sep 2013 04:21:51 -0700 (PDT) In-Reply-To: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> Date: Wed, 18 Sep 2013 21:21:51 +1000 Subject: Re: iterating over a file with two pointers From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 13 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1379503314 news.xs4all.nl 15972 [2001:888:2000:d::a6]:46923 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54370 On Wed, Sep 18, 2013 at 9:12 PM, nikhil Pandey wrote: > hi, > I want to iterate over the lines of a file and when i find certain lines, i need another loop starting from the next of that "CERTAIN" line till a few (say 20) lines later. > so, basically i need two pointers to lines (one for outer loop(for each line in file)) and one for inner loop. How can i do that in python? > please help. I am stuck up on this. After the inner loop finishes, do you want to go back to where the outer loop left off, or should the outer loop continue from the point where the inner loop stopped? In other words, do you want to locate overlapping sections, or not? Both are possible, but the solutions will look somewhat different. ChrisA