[Tutor] Tutor Digest, Vol 28, Issue 10

Kermit Rose kermit at polaris.net
Tue Jun 6 21:25:44 CEST 2006

From: tutor-request at python.org
Date: 06/06/06 12:31:25
To: tutor at python.org
Subject: Tutor Digest, Vol 28, Issue 10
Message: 9
Date: Tue, 06 Jun 2006 12:21:51 -0400
From: Kent Johnson <kent37 at tds.net>
Subject: Re: [Tutor] Reading characters from file in binary mode
To: Python Tutor <tutor at 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))
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
what is that something else?
Kermit   <  kermit at polaris.net  >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060606/798770c9/attachment.htm 
-------------- 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/798770c9/attachment.jpe 

More information about the Tutor mailing list