<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">It looks like <font face="Courier" class="">read()</font> is returning a string, then the <font face="Courier" class="">for</font> loop is actually looping through that string one character at a time.<div class=""><br class=""></div><div class="">If each of the records are on one line, you can simply iterate over the file:   <font face="Courier" class="">for line in fp: ...</font></div><div class=""><div class=""><br class=""></div><div class="">If not, you should turn your loop into:</div><div class=""><br class=""></div><div class=""><font face="Courier" class="">while True:</font></div><div class=""><font face="Courier" class="">    line = fp.read(26)</font></div><div class=""><font face="Courier" class="">    if len(line) < 26: break</font></div><div class=""><font face="Courier" class="">    ...</font></div><div class=""><br class=""></div><div class="">Or be fancy with a generator (I assume that’s in python2.4?):</div><div class=""><br class=""></div><div class=""><font face="Courier" class="">def next_record(file):</font></div><div class=""><font face="Courier" class="">    while True:</font></div><div class=""><font face="Courier" class="">    line = fp.read(26)</font></div><div class=""><font face="Courier" class="">    if len(line) < 26: raise StopIteration</font></div><font face="Courier" class=""><em class="property"></em><a class="headerlink" href="https://docs.python.org/2/library/exceptions.html#exceptions.StopIteration" title="Permalink to this definition"></a></font><div class=""><font face="Courier" class="">    yield line</font></div><div class=""><br class=""></div><div class=""><font face="Courier" class="">for record in next_record(fp):</font></div><div class=""><font face="Courier" class="">    ...</font></div><div class="">  </div><div class="">- Andrew Kubera</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 20, 2015, at 11:04 AM, Joshua Kramer <<a href="mailto:joskra42.list@gmail.com" class="">joskra42.list@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">Hello all!<br class=""><br class="">I have a rather bizarre issue reading files that came from an IBM<br class="">Mainframe.  I am on a Linux server, FTP'ing the files from the<br class="">Mainframe, and running a Python script.  It seems like the Python<br class="">script always reads just one byte at a time from the file!  For<br class="">example, if you have a file with records like this (this is two<br class="">records, each one being of length 26):<br class=""><br class="">00423SMITH   JOHN  126400100423SMITH   ROBERT1264001<br class=""><br class="">If you open this file with any text editor on Linux, it appears as it is there.<br class=""><br class="">If I do this in Python:<br class=""><br class="">fp = open("FILE.DAT", "rb")<br class="">for line in fp.read(26):<br class="">    print "Record is: " + line<br class=""><br class="">Then what I will get is this:<br class="">Record is: 0<br class="">Record is: 0<br class="">Record is: 4<br class="">Record Is: 2<br class="">Record Is: 3<br class="">...etcetera.<br class=""><br class="">I wrote the same program in C, and I got the results I expected- not<br class="">these results.  So I have reason to believe that the file is good.<br class=""><br class="">I am using Python 2.4.3.  (Unfortunately, stuck on an ancient RedHat server...)<br class=""><br class="">What am I missing here?<br class=""><br class="">Thanks!<br class="">-JK<br class="">_______________________________________________<br class="">CentralOH mailing list<br class=""><a href="mailto:CentralOH@python.org" class="">CentralOH@python.org</a><br class="">https://mail.python.org/mailman/listinfo/centraloh<br class=""></div></blockquote></div><br class=""></div></div></body></html>