mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Merged revisions 60234-60244 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r60234 | gregory.p.smith | 2008-01-24 10:38:26 +0100 (Thu, 24 Jan 2008) | 4 lines Fix issue1789: The tutorial contained a misuse of the struct module. (also remove an unneeded import struct from test_largefile) ........ r60237 | vinay.sajip | 2008-01-24 13:37:08 +0100 (Thu, 24 Jan 2008) | 1 line Added optional delay argument to FileHandler and subclasses. ........ r60238 | vinay.sajip | 2008-01-24 13:37:33 +0100 (Thu, 24 Jan 2008) | 1 line Added optional delay argument to FileHandler and subclasses. ........ r60239 | vinay.sajip | 2008-01-24 13:38:30 +0100 (Thu, 24 Jan 2008) | 1 line Added documentation for optional delay argument to FileHandler and subclasses. ........ r60240 | vinay.sajip | 2008-01-24 13:43:33 +0100 (Thu, 24 Jan 2008) | 1 line Updated for optional delay argument to FileHandler and subclasses. ........ r60243 | guido.van.rossum | 2008-01-24 16:53:22 +0100 (Thu, 24 Jan 2008) | 2 lines Fi debug turd -- a call accidentally left out. ........
This commit is contained in:
parent
e83ebd9ab1
commit
e7a15bb808
6 changed files with 59 additions and 29 deletions
|
@ -134,8 +134,10 @@ Working with Binary Data Record Layouts
|
|||
|
||||
The :mod:`struct` module provides :func:`pack` and :func:`unpack` functions for
|
||||
working with variable length binary record formats. The following example shows
|
||||
how to loop through header information in a ZIP file (with pack codes ``"H"``
|
||||
and ``"L"`` representing two and four byte unsigned numbers respectively)::
|
||||
how to loop through header information in a ZIP file without using the
|
||||
:mod:`zipfile` module. Pack codes ``"H"`` and ``"I"`` represent two and four
|
||||
byte unsigned numbers respectively. The ``"<"`` indicates that they are
|
||||
standard size and in little-endian byte order::
|
||||
|
||||
import struct
|
||||
|
||||
|
@ -143,7 +145,7 @@ and ``"L"`` representing two and four byte unsigned numbers respectively)::
|
|||
start = 0
|
||||
for i in range(3): # show the first 3 file headers
|
||||
start += 14
|
||||
fields = struct.unpack('LLLHH', data[start:start+16])
|
||||
fields = struct.unpack('<IIIHH', data[start:start+16])
|
||||
crc32, comp_size, uncomp_size, filenamesize, extra_size = fields
|
||||
|
||||
start += 16
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue