Hello All,<div><br></div><div>Say I have something like this:</div><div><br></div><div><div>mfile = open("cc.txt", "rb")</div><div>mcount = 0</div><div>mset = False</div><div>while True:</div><div><span class="Apple-tab-span" style="white-space:pre">    </span>c = mfile.read(1)</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>if c == "e" and mset is True and mcount == 0:</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>    print c</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>    mfile.seek(-1,1)</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>    mcount = 1</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>    continue</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>elif c == "e" and mset is False and mcount == 0:</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>    print c</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>    mfile.seek(-1, 0)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>    mcount = 1</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>    continue</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>elif c == "e" and mcount == 1:</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>    print c</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>    mcount = 0</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>    continue</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>print c</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span></div><div><span class="Apple-tab-span" style="white-space:pre">     </span>if mset is False:</div><div><span class="Apple-tab-span" style="white-space:pre">    </span>    mset = True</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>if len(c) == 0:</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>    break</div><div><br></div><div>cc.txt</div><div><br></div><div><div>
foor the this the been we hate to sh wiukr bee here today. But who are we to question </div><div>him concerning this issue.</div></div><div><br></div><div>Is the above code the right way?</div><div><br></div><div>Regards, \Emeka</div>
<br><div class="gmail_quote">On Sat, Feb 18, 2012 at 5:17 AM, Emeka <span dir="ltr"><<a href="mailto:emekamicro@gmail.com">emekamicro@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Neil,<div><br></div><div>Thanks. Could you throw a simple example?</div><div><br></div><div>Regards, \Emeka<div><div class="h5"><br><br><div class="gmail_quote">On Fri, Feb 17, 2012 at 3:12 PM, Neil Cerutti <span dir="ltr"><<a href="mailto:neilc@norwich.edu" target="_blank">neilc@norwich.edu</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On 2012-02-16, MRAB <<a href="mailto:python@mrabarnett.plus.com" target="_blank">python@mrabarnett.plus.com</a>> wrote:<br>


> On 16/02/2012 23:10, Emeka wrote:<br>
</div><div>>> Hello All,<br>
>><br>
>> I know about seek and tell while using readline. What about if I am<br>
>> using read, and I want to undo the last character I just read(to return<br>
>> it back to the stream). How do I achieve this?<br>
>><br>
</div><div>> Try:<br>
><br>
>      f.seek(-1, 1)<br>
><br>
> It seeks -1 relative to the current position (the second<br>
> argument defaults to 0 for relative to start of file).<br>
<br>
</div>Unless it's a stream opened in binary mode this will not work.<br>
You'd need to maintain a n-character length buffer instead, with<br>
n being the maximum number of characters you'd like to be able to<br>
put back.<br>
<span><font color="#888888"><br>
--<br>
Neil Cerutti<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><i>Satajanus  Nig. Ltd<br><br><br></i><br>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><i>Satajanus  Nig. Ltd<br><br><br></i><br>
</div>