Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #44442

Re: File Read issue by using module binascii

References <9b5795ab-baec-4c0a-a3b4-1075cffc8744@googlegroups.com> <be399492-2c63-40f6-840d-ccefa8f78218@googlegroups.com>
Date 2013-04-27 10:56 +0100
Subject Re: File Read issue by using module binascii
From Fábio Santos <fabiosantosart@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1121.1367056577.3114.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

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" <jimmie.he@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
>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

File Read issue by using module binascii Jimmie He <jimmie.he@gmail.com> - 2013-04-26 20:57 -0700
  Re: File Read issue by using module binascii Jimmie He <jimmie.he@gmail.com> - 2013-04-26 21:22 -0700
    Re: File Read issue by using module binascii Fábio Santos <fabiosantosart@gmail.com> - 2013-04-27 10:56 +0100
      Re: File Read issue by using module binascii Jimmie He <jimmie.he@gmail.com> - 2013-04-27 03:42 -0700
  Re: File Read issue by using module binascii Peter Otten <__peter__@web.de> - 2013-04-27 12:57 +0200
    Re: File Read issue by using module binascii Jimmie He <jimmie.he@gmail.com> - 2013-04-27 04:23 -0700
      Re: File Read issue by using module binascii Fábio Santos <fabiosantosart@gmail.com> - 2013-04-27 12:40 +0100
      Re: File Read issue by using module binascii Peter Otten <__peter__@web.de> - 2013-04-27 14:01 +0200
  Re: File Read issue by using module binascii Jimmie He <jimmie.he@gmail.com> - 2013-04-27 05:46 -0700
  Re: File Read issue by using module binascii Tim Roberts <timr@probo.com> - 2013-04-27 21:34 -0700
    Re: File Read issue by using module binascii Peter Otten <__peter__@web.de> - 2013-04-28 09:42 +0200
    Re: File Read issue by using module binascii jt@toerring.de (Jens Thoms Toerring) - 2013-04-28 12:04 +0000
      Re: File Read issue by using module binascii Jimmie He <jimmie.he@gmail.com> - 2013-04-28 06:32 -0700

csiph-web