Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Dennis Lee Bieber Newsgroups: comp.lang.python Subject: Re: Problems using struct pack/unpack in files, and reading them. Date: Fri, 13 Nov 2015 19:46:16 -0500 Organization: IISS Elusive Unicorn Lines: 29 Message-ID: References: <20151113192045.GA9913@z-sverige.nu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de wOyRln6GS0K1YmbkRlBkzwWxG0Gbi/PoJSzOmV7flYRA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'tmp': 0.07; 'message- id:@4ax.com': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:[ 30': 0.09; 'subject:files': 0.09; 'subject:using': 0.09; 'syntax': 0.13; 'file,': 0.15; 'skip:p 40': 0.15; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'structure.': 0.16; 'subject:Problems': 0.16; 'url:home': 0.18; '2015': 0.20; 'performing': 0.23; 'represents': 0.23; 'header:X-Complaints-To:1': 0.26; 'fri,': 0.27; '-0500,': 0.29; 'subject:/': 0.30; 'supposed': 0.31; 'probably': 0.31; 'file': 0.34; 'nov': 0.35; 'skip:p 30': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'received:org': 0.37; 'desired': 0.37; 'charset :us-ascii': 0.37; 'whatever': 0.39; 'to:addr:python.org': 0.40; 'entire': 0.61; 'kent': 0.84; 'subject:pack': 0.84; 'dennis': 0.91; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: adsl-108-68-178-61.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:98783 On Fri, 13 Nov 2015 14:20:45 -0500, kent nyberg declaimed the following: > tmp = place_to_read.read()[RegisterAX:calcsize('HH')] You've just read the ENTIRE FILE, and only kept whatever "RegisterAX" represents to the size of the structure. If "RegisterAX" is supposed to indicate "where to start", you probably need to be using [RegisterAX:RegisterAX+calcsize("HH")] Though you probably really need to be performing a seek() on the file first to locate the start of what you want to read place_to_read.seek(RegisterAX) #check the syntax for #from start of file tmp = place_to_read.read()[:calcsize("HH")] But it may be even better to just read the desired number of bytes... tmp = place_to_read.read(calcsize("HH")) #still need the seek() -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/