<br><br><div class="gmail_quote">On Thu, Sep 16, 2010 at 7:36 PM, Jean Luc Truchtersheim <span dir="ltr"><<a href="mailto:jeanluc434@gmail.com">jeanluc434@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hello,<br>
<br>
I am trying to read from stdin and dump what's read to a temporary<br>
file. My code works for small files but as soon as I have a file that<br>
has, e.g., more than 300 lines, there is always one and only one line<br>
that is truncated compared to the input.<br>
<br>
Here is my code:<br>
#---------------------------------------------------------------------------------<br>
#! /usr/bin/env python<br>
<br>
import sys<br>
from tempfile import *<br>
<br>
if __name__ == "__main__":<br>
        data = []<br>
        f_in = NamedTemporaryFile(suffix=".txt", delete=False)<br>
        for line in sys.stdin:<br>
                f_in.write(line)<br>
                data.append(line)<br>
        f_in.close<br></blockquote><div><br>Does this need to be f_in.close() ?<br> <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

        f = open(<a href="http://f_in.name" target="_blank">f_in.name</a>, 'rb')<br>
        i=0<br>
        for line in f:<br>
                if data[i] != line:<br>
                        print >>sys.stderr, "line %d:\nfile(%d):\"%s\"\narray(%d):\"%s\"" %<br>
(i+1, len(line), line, len(data[i]), data[i])<br>
                i += 1<br>
        sys.exit()<br>
#-------------------------------------------------------------------------------------------------<br>
<br>
I feel that I must be doing something very stupid, but I don't really<br>
know what.<br>
<br>
Any idea?<br>
<br>
Can anybody reproduce this behavior.<br>
<br>
Thanks a bunch for any help.<br>
<br>
Jean Luc.<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Jason M. Swails<br>Quantum Theory Project,<br>University of Florida<br>Ph.D. Graduate Student<br>352-392-4032<br>