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">&lt;<a href="mailto:andreengels@gmail.com">andreengels@gmail.com</a>&gt;</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 &lt;<a href="mailto:ranjand2005@gmail.com">ranjand2005@gmail.com</a>&gt; wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; I am new to python and i wrote this piece of code which is ofcourse not<br>
&gt; serving my purpose:<br>
&gt;<br>
&gt; Aim of the code:<br>
&gt;<br>
&gt; To read a file and look for lines which contain the string &#39;CL&#39;. When found,<br>
&gt; print the entry of the next line (positioned directly below the string &#39;CL&#39;)<br>
&gt; ....continue to do this till the end of the file (since there are more than<br>
&gt; one occurrences of &#39;CL&#39; in the file)<br>
&gt;<br>
&gt; My piece of code (which just prints lines which contain the string &#39;CL&#39;)<br>
&gt;<br>
&gt; f=open(&#39;somefile.txt&#39;,&#39;r&#39;)<br>
&gt;<br>
&gt; for line in f.readlines():<br>
&gt;<br>
&gt;      if &#39;CL&#39; in line:<br>
&gt;               print line<br>
&gt;<br>
&gt;<br>
&gt; please suggest how do i print the entry right below the string &#39;CL&#39;<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 = &#39;CL&#39; in line<br>
<br>
(I assume the last line does not contain &#39;CL&#39;, 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>