Thanks a lot Andre...it is working <br><br><div class="gmail_quote">On Sat, Sep 12, 2009 at 2:17 PM, Andre Engels <span dir="ltr"><<a href="mailto:andreengels@gmail.com">andreengels@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">On Sat, Sep 12, 2009 at 10:35 AM, ranjan das <<a href="mailto:ranjand2005@gmail.com">ranjand2005@gmail.com</a>> wrote:<br>
> Hi,<br>
><br>
> I am new to python and i wrote this piece of code which is ofcourse not<br>
> serving my purpose:<br>
><br>
> Aim of the code:<br>
><br>
> To read a file and look for lines which contain the string 'CL'. When found,<br>
> print the entry of the next line (positioned directly below the string 'CL')<br>
> ....continue to do this till the end of the file (since there are more than<br>
> one occurrences of 'CL' in the file)<br>
><br>
> My piece of code (which just prints lines which contain the string 'CL')<br>
><br>
> f=open('somefile.txt','r')<br>
><br>
> for line in f.readlines():<br>
><br>
> if 'CL' in line:<br>
> print line<br>
><br>
><br>
> please suggest how do i print the entry right below the string 'CL'<br>
<br>
</div>I would this using a boolean variable to denote whether the line<br>
should be printed:<br>
<br>
printline = false<br>
<div class="im">for line in f.readlines():<br>
</div> if printline:<br>
print line<br>
printline = 'CL' in line<br>
<br>
(I assume the last line does not contain 'CL', because otherwise we<br>
have a problem with the problem definition)<br>
<font color="#888888"><br>
--<br>
André Engels, <a href="mailto:andreengels@gmail.com">andreengels@gmail.com</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>The inherent vice of capitalism is the unequal sharing of blessings; the inherent virtue of socialism is the equal sharing of miseries. <br><br>~ Winston Churchill<br>