[Python-checkins] r60234 - in python/trunk: Doc/library/struct.rst Doc/tutorial/stdlib2.rst Lib/test/test_largefile.py

gregory.p.smith python-checkins at python.org
Thu Jan 24 10:38:27 CET 2008


Author: gregory.p.smith
Date: Thu Jan 24 10:38:26 2008
New Revision: 60234
Modified:
 python/trunk/Doc/library/struct.rst
 python/trunk/Doc/tutorial/stdlib2.rst
 python/trunk/Lib/test/test_largefile.py
Log:
Fix issue1789: The tutorial contained a misuse of the struct module.
(also remove an unneeded import struct from test_largefile)
Modified: python/trunk/Doc/library/struct.rst
==============================================================================
--- python/trunk/Doc/library/struct.rst	(original)
+++ python/trunk/Doc/library/struct.rst	Thu Jan 24 10:38:26 2008
@@ -85,7 +85,7 @@
 +--------+-------------------------+--------------------+-------+
 | ``i`` | :ctype:`int` | integer | |
 +--------+-------------------------+--------------------+-------+
-| ``I`` | :ctype:`unsigned int` | long | |
+| ``I`` | :ctype:`unsigned int` | integer or long | |
 +--------+-------------------------+--------------------+-------+
 | ``l`` | :ctype:`long` | integer | |
 +--------+-------------------------+--------------------+-------+
@@ -104,7 +104,7 @@
 +--------+-------------------------+--------------------+-------+
 | ``p`` | :ctype:`char[]` | string | |
 +--------+-------------------------+--------------------+-------+
-| ``P`` | :ctype:`void \*` | integer | |
+| ``P`` | :ctype:`void \*` | long | |
 +--------+-------------------------+--------------------+-------+
 
 Notes:
Modified: python/trunk/Doc/tutorial/stdlib2.rst
==============================================================================
--- python/trunk/Doc/tutorial/stdlib2.rst	(original)
+++ python/trunk/Doc/tutorial/stdlib2.rst	Thu Jan 24 10:38:26 2008
@@ -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
Modified: python/trunk/Lib/test/test_largefile.py
==============================================================================
--- python/trunk/Lib/test/test_largefile.py	(original)
+++ python/trunk/Lib/test/test_largefile.py	Thu Jan 24 10:38:26 2008
@@ -6,7 +6,7 @@
 #----------------------------------------------------------------------
 
 from test import test_support
-import os, struct, stat, sys
+import os, stat, sys
 
 try:
 import signal


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /