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


Groups > comp.lang.python > #44447

Re: File Read issue by using module binascii

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'output': 0.05; 'filing': 0.07; 'modify': 0.07; 'python3': 0.07; 'sys': 0.07; '"__main__":': 0.09; '__name__': 0.09; 'f.close()': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:module': 0.09; 'subject:using': 0.09; 'python': 0.11; 'def': 0.12; 'windows': 0.15; '(about': 0.16; '/dev/null': 0.16; 'hex': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:File': 0.16; 'subject:issue': 0.16; 'tweak': 0.16; 'wrote:': 0.18; 'import': 0.22; '(in': 0.22; 'shell': 0.22; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'header:X-Complaints- To:1': 0.27; 'url:bugs': 0.29; 'dos': 0.30; 'skip:( 20': 0.30; 'code': 0.31; 'usually': 0.31; 'terminate': 0.31; 'yes.': 0.31; 'quite': 0.32; 'linux': 0.33; 'url:python': 0.33; 'skip:# 10': 0.33; 'could': 0.34; 'problem.': 0.35; 'but': 0.35; 'version': 0.36; 'idle': 0.36; 'similar': 0.36; 'url:org': 0.36; 'seconds': 0.37; 'operating': 0.37; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'expect': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'hardware': 0.61; 'numbers': 0.61; 'first': 0.61; 'real': 0.63; 'confirm': 0.64; 'user,': 0.69; 'yourself': 0.78; 'faster.': 0.84; 'old.': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: File Read issue by using module binascii
Date Sat, 27 Apr 2013 14:01:35 +0200
Organization None
References <9b5795ab-baec-4c0a-a3b4-1075cffc8744@googlegroups.com> <mailman.1122.1367060234.3114.python-list@python.org> <2441ce7d-8b3a-405f-ab88-d4e772191eb4@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p5084a971.dip0.t-ipconnect.de
User-Agent KNode/4.7.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1124.1367064104.3114.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1367064104 news.xs4all.nl 15952 [2001:888:2000:d::a6]:48918
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:44447

Show key headers only | View raw


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

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