Date: 06/06/06 12:31:25
Subject: Tutor Digest, Vol 28, Issue 10
 
 
Message: 9
Date: Tue, 06 Jun 2006 12:21:51 -0400
From: Kent Johnson <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Reading characters from file in binary mode
To: Python Tutor <tutor@python.org>
 
 
Hmm, my C++ is remarkably rusty but I think you want something like this:
 
inp = open("CMT_MCAID", "rb")
out = open("mcaid.txt", "w")
 
for i in range(1000):
   ch = inp.read(1)
   if not ch: break # EOF
   k = ord(ch) # convert to integer
   kl = k % 16
   kh = k / 16
   out.write('%x %x ' % (kh, kl))
out.close()
 
*******
 
Thank you very much.  It looks exactly what I wished to know.
 
But now, I realize that I don't know how to invoke Python to compile and execute the
program file.
 
I will be making rapid changes to the file, and recompiling over and over again as
I change the program during my experimentation.
 
I guess that in the open command,  the  rb stands for read and something else. 
what is that something else?
 
Kermit   <  [EMAIL PROTECTED]  >
 
 
 
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to