Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98783
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Problems using struct pack/unpack in files, and reading them. |
| Date | 2015-11-13 19:46 -0500 |
| Organization | IISS Elusive Unicorn |
| Message-ID | <mailman.313.1447461981.16136.python-list@python.org> (permalink) |
| References | <20151113192045.GA9913@z-sverige.nu> |
On Fri, 13 Nov 2015 14:20:45 -0500, kent nyberg <kent@z-sverige.nu>
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/
Back to comp.lang.python | Previous | Next | Find similar
Re: Problems using struct pack/unpack in files, and reading them. Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-11-13 19:46 -0500
csiph-web