Fix issue1789: The tutorial contained a misuse of the struct module.

(also remove an unneeded import struct from test_largefile)
This commit is contained in:
Gregory P. Smith 2008-01-24 09:38:26 +00:00
parent 7070094d7f
commit 7b7ce7854c
3 changed files with 8 additions and 6 deletions

View file

@ -85,7 +85,7 @@ Python values should be obvious given their types:
+--------+-------------------------+--------------------+-------+ +--------+-------------------------+--------------------+-------+
| ``i`` | :ctype:`int` | integer | | | ``i`` | :ctype:`int` | integer | |
+--------+-------------------------+--------------------+-------+ +--------+-------------------------+--------------------+-------+
| ``I`` | :ctype:`unsigned int` | long | | | ``I`` | :ctype:`unsigned int` | integer or long | |
+--------+-------------------------+--------------------+-------+ +--------+-------------------------+--------------------+-------+
| ``l`` | :ctype:`long` | integer | | | ``l`` | :ctype:`long` | integer | |
+--------+-------------------------+--------------------+-------+ +--------+-------------------------+--------------------+-------+
@ -104,7 +104,7 @@ Python values should be obvious given their types:
+--------+-------------------------+--------------------+-------+ +--------+-------------------------+--------------------+-------+
| ``p`` | :ctype:`char[]` | string | | | ``p`` | :ctype:`char[]` | string | |
+--------+-------------------------+--------------------+-------+ +--------+-------------------------+--------------------+-------+
| ``P`` | :ctype:`void \*` | integer | | | ``P`` | :ctype:`void \*` | long | |
+--------+-------------------------+--------------------+-------+ +--------+-------------------------+--------------------+-------+
Notes: Notes:

View file

@ -134,8 +134,10 @@ Working with Binary Data Record Layouts
The :mod:`struct` module provides :func:`pack` and :func:`unpack` functions for The :mod:`struct` module provides :func:`pack` and :func:`unpack` functions for
working with variable length binary record formats. The following example shows 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"`` how to loop through header information in a ZIP file without using the
and ``"L"`` representing two and four byte unsigned numbers respectively):: :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 import struct
@ -143,7 +145,7 @@ and ``"L"`` representing two and four byte unsigned numbers respectively)::
start = 0 start = 0
for i in range(3): # show the first 3 file headers for i in range(3): # show the first 3 file headers
start += 14 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 crc32, comp_size, uncomp_size, filenamesize, extra_size = fields
start += 16 start += 16

View file

@ -6,7 +6,7 @@
#---------------------------------------------------------------------- #----------------------------------------------------------------------
from test import test_support from test import test_support
import os, struct, stat, sys import os, stat, sys
try: try:
import signal import signal