Mercurial > cpython-lru_cache-weakref
diff Doc/tutorial/stdlib2.rst @ 44904:063ed377fd3d legacy-trunk
Fix issue1789: The tutorial contained a misuse of the struct module.
(also remove an unneeded import struct from test_largefile)
| author | Gregory P. Smith <greg@mad-scientist.com> |
|---|---|
| date | Thu, 24 Jan 2008 09:38:26 +0000 |
| parents | 1e266015cf5b |
| children | bc9fd84afdec |
line wrap: on
line diff
--- a/Doc/tutorial/stdlib2.rst Thu Jan 24 07:40:51 2008 +0000 +++ b/Doc/tutorial/stdlib2.rst Thu Jan 24 09:38:26 2008 +0000 @@ -134,8 +134,10 @@ 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 @@ 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
