Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'anyway.': 0.05; 'f.close()': 0.09; 'subject:module': 0.09; 'subject:using': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'windows': 0.15; 'advance!': 0.16; 'chunks': 0.16; 'hex': 0.16; 'loop.': 0.16; 'looping': 0.16; 'once.': 0.16; 'subject:File': 0.16; 'subject:issue': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'starts': 0.20; 'memory': 0.22; 'import': 0.22; 'email addr:gmail.com>': 0.22; 'shell': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'this?': 0.23; 'processor': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'header:In- Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'file': 0.32; 'run': 0.32; 'url:python': 0.33; 'skip:# 10': 0.33; 'maybe': 0.34; 'problem': 0.35; 'received:209.85': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'right?': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'should': 0.36; 'too': 0.37; 'received:209': 0.37; 'skip:o 20': 0.38; 'skip:& 10': 0.38; 'thank': 0.38; 'itself': 0.39; 'url:mail': 0.40; 'tell': 0.60; 'become': 0.64; 'taking': 0.65; 'to:addr:gmail.com': 0.65; '8bit%:60': 0.84; 'trouble.': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=++tHec7bKZQpiX0MqU5sZt0agxG15J1YDJXq5QdwQ/c=; b=mHTMt7E13yr1CDQj1GZz08A+W773mUiGj/4uKosOidvJXHFNMGJT4nHoSWwvuWRanw Ttp4gMe8pHPBoMV9OiFayq0rp3aB27Nr/0PtMvFTAOeCf/7lyFYi8SsKsU8Rrs1XO1cU KRAiG3WGxQCsHKUrgyMKDzTnHYgw/w7iCs3TGy6cEuxZ8Et1vUZU9lM+seS9XFk8h0Gb jjGtSAZF55v02pVqptrwgm8pZeOsDk/NssdUkdrdq+RlKk5t67F33Eac9JU0+jT2XKcu Z0kyWkYx8TaJRp+XWQAzonZYxEDxpzxyzNF9LFpF5k6lpn1YBmipZPsj2kaBKPTnA5Nr 05zw== MIME-Version: 1.0 X-Received: by 10.49.104.145 with SMTP id ge17mr38163599qeb.59.1367056568451; Sat, 27 Apr 2013 02:56:08 -0700 (PDT) In-Reply-To: References: <9b5795ab-baec-4c0a-a3b4-1075cffc8744@googlegroups.com> Date: Sat, 27 Apr 2013 10:56:08 +0100 Subject: Re: File Read issue by using module binascii From: =?ISO-8859-1?Q?F=E1bio_Santos?= To: Jimmie He Content-Type: multipart/alternative; boundary=047d7b5d8fc526871404db54a9ac Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 117 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1367056577 news.xs4all.nl 15916 [2001:888:2000:d::a6]:40388 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44442 --047d7b5d8fc526871404db54a9ac Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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" 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......A= m > I right? > > =E5=9C=A8 2013=E5=B9=B44=E6=9C=8827=E6=97=A5=E6=98=9F=E6=9C=9F=E5=85=ADUT= C+8=E4=B8=8A=E5=8D=8811=E6=97=B657=E5=88=8645=E7=A7=92=EF=BC=8CJimmie He=E5= =86=99=E9=81=93=EF=BC=9A > > When I run the readbmp on an example.bmp(about 100k),the Shell is becom= e > 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 =3D open('example.bmp','rb') > > > > rawdata =3D f.read() #f.read(1000) is ok > > > > hexstr =3D binascii.b2a_hex(rawdata) #Get an HEX number > > > > bsstr =3D bin (int(hexstr,16))[2:] > > > > f.close() > > > > print('bin: ',bsstr,type(bsstr)) > > > > return > -- > http://mail.python.org/mailman/listinfo/python-list > --047d7b5d8fc526871404db54a9ac Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

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 cons= ole may be having trouble. Try looping over small chunks of the file and pr= inting 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)) &q= uot;,it can be run,so maybe the problem is the memory allocate of so long s= trings......Am I right?

=E5=9C=A8 2013=E5=B9=B44=E6=9C=8827=E6=97=A5=E6=98=9F=E6=9C=9F=E5=85=ADUTC+= 8=E4=B8=8A=E5=8D=8811=E6=97=B657=E5=88=8645=E7=A7=92=EF=BC=8CJimmie He=E5= =86=99=E9=81=93=EF=BC=9A
> When I run the readbmp on an example.bmp(about 100k),the Shell is beco= me to "No respose",when I change f.read() to f.read(1000),it is o= k,could someone tell me the excat reason for this?
>
> Thank you in advance!
>
>
>
> Python Code as below!!
>
>
>
> import binascii
>
>
>
> def read_bmp():
>
> =C2=A0 =C2=A0 f =3D open('example.bmp','rb')
>
> =C2=A0 =C2=A0 rawdata =3D f.read() =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 #f.read(1000) is ok
>
> =C2=A0 =C2=A0 hexstr =3D binascii.b2a_hex(rawdata) =C2=A0 =C2=A0 =C2= =A0 #Get an HEX number
>
> =C2=A0 =C2=A0 bsstr =3D bin (int(hexstr,16))[2:]
>
> =C2=A0 =C2=A0 f.close()
>
> =C2=A0 =C2=A0 print('bin: ',bsstr,type(bsstr))
>
> =C2=A0 =C2=A0 return
--
http://mail.python.org/mailman/listinfo/python-list
--047d7b5d8fc526871404db54a9ac--