[CentralOH] Weird issue reading a Mainframe file with Python

Joshua Kramer joskra42.list at gmail.com
Wed May 20 17:04:16 CEST 2015


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


More information about the CentralOH mailing list