File Read issue by using module binascii

Jimmie He jimmie.he at gmail.com
Sat Apr 27 06:42:58 EDT 2013


What you said should make sense and I've already correct my code by your advice,thanks for your response!


在 2013年4月27日星期六UTC+8下午5时56分08秒,Fábio Santos写道:
> It may be that you are printing too much data at once. 100k is a bit too much to have in memory but it should run anyway. But your console may be having trouble. Try looping over small chunks of the file and printing them one at a time. Use a while loop. I do know that in windows the console is not very efficient at printing so when I print too much data the console itself starts taking up a lot of processor time.
> 
> 
> On 27 Apr 2013 05:28, "Jimmie He" <jimm... at gmail.com> wrote:
> 
> when I commet the line of "print('bin: ',bsstr,type(bsstr)) ",it can be run,so maybe the problem is the memory allocate of so long strings......Am I right?
> 
> 
> 
> 在 2013年4月27日星期六UTC+8上午11时57分45秒,Jimmie He写道:
> 
> > When I run the readbmp on an example.bmp(about 100k),the Shell is become to "No respose",when I change f.read() to f.read(1000),it is ok,could someone tell me the excat reason for this?
> 
> >
> 
> > Thank you in advance!
> 
> >
> 
> >
> 
> >
> 
> > Python Code as below!!
> 
> >
> 
> >
> 
> >
> 
> > 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
> 
> --
> 
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list