[CentralOH] Weird issue reading a Mainframe file with Python

Bryan Harris brywilharris at gmail.com
Wed May 20 17:24:44 CEST 2015


"rb" means "read binary", try just "r"

Bryan Harris, PE
Research Engineer
Structures and Materials Evaluation Group
University of Dayton Research Institute
bryan.harris at udri.udayton.edu
http://www.udri.udayton.edu/
(937) 229-5561

On Wed, May 20, 2015 at 11:04 AM, Joshua Kramer <joskra42.list at gmail.com>
wrote:

> Hello all!
>
> I have a rather bizarre issue reading files that came from an IBM
> Mainframe.  I am on a Linux server, FTP'ing the files from the
> Mainframe, and running a Python script.  It seems like the Python
> script always reads just one byte at a time from the file!  For
> example, if you have a file with records like this (this is two
> records, each one being of length 26):
>
> 00423SMITH   JOHN  126400100423SMITH   ROBERT1264001
>
> If you open this file with any text editor on Linux, it appears as it is
> there.
>
> If I do this in Python:
>
> fp = open("FILE.DAT", "rb")
> for line in fp.read(26):
>     print "Record is: " + line
>
> Then what I will get is this:
> Record is: 0
> Record is: 0
> Record is: 4
> Record Is: 2
> Record Is: 3
> ...etcetera.
>
> I wrote the same program in C, and I got the results I expected- not
> these results.  So I have reason to believe that the file is good.
>
> I am using Python 2.4.3.  (Unfortunately, stuck on an ancient RedHat
> server...)
>
> What am I missing here?
>
> Thanks!
> -JK
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> https://mail.python.org/mailman/listinfo/centraloh
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20150520/17cca412/attachment.html>


More information about the CentralOH mailing list