File Read issue by using module binascii
Peter Otten
__peter__ at web.de
Sat Apr 27 08:01:35 EDT 2013
Jimmie He wrote:
>> What shell are you using? The one provided by Idle?
>
> Yes. I use IDLE,the python version is 3.3.1.What else could I use??
The shell provided by the operating system is usually much faster. When I
modify your code to
import binascii
def read_bmp():
f = open('example.bmp','rb')
rawdata = f.read() #f.read(1000) is ok
hexstr = binascii.b2a_hex(rawdata) #Get an HEX number
bsstr = bin (int(hexstr,16))[2:]
f.close()
print('bin: ',bsstr,type(bsstr))
return
if __name__ == "__main__":
read_bmp()
and generate a dummy example.bmp with 2**20 (about 1 million) bytes it takes
about 2 seconds to terminate -- on hardware that is quite old. If I redirect
the output it is even faster:
$ time python3 bmp_to_bin.py > /dev/null
real 0m0.766s
user 0m0.300s
sys 0m0.180s
I am a Linux user, but expect similar numbers on Windows (in the DOS box or
one of its successors).
I have considered filing a bug* to ask for a tweak in idle that improves its
responsiveness, but first wanted you to confirm that this was indeed the
problem.
(*) on http://bugs.python.org, if you want to do it yourself
More information about the Python-list
mailing list