[Tutor] Reading characters from file in binary mode

Kermit Rose kermit at polaris.net
Tue Jun 6 15:07:40 CEST 2006

I wish to translate a SAS data file to text, and do not have the
version of SAS to do so.
I have the student version of SAS, and have translated the shortest of 4 SAS
data sets given.
For the other 3, I wish to construct a python program to read the characters
in, one
at a time, translate them to hexadecimal, then figure out how the data
the data dictionary that I have.
I experimented with writing code in C++ to do this.
My first experiment, in C++  is
#include <stdio.h>
#include <iostream>
#define TRUE    1                       /* Define some handy constants  */
#define FALSE   0                       /* Define some handy constants  */
ifstream f("CMT_MCAID",ios_base::binary);
ofstream G("mcaid.txt",ios_base::app);
char ch
int k
int kh,kl
int limit
limit = 1000
for (int I=1;I<= limit;I++) 
f >> ch;
k = ch;
kl = k%16;
kh = (k -kl)/16;
G << kh," ",kl," ";
How can I begin to experiment using python?  What would be python code
to the above C++ code?
Kermit  <  kermit at Polaris.net  >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060606/92862444/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 1431 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20060606/92862444/attachment.jpe 

More information about the Tutor mailing list