Skip to content

Commit 661a1c5

Browse files
committed
Update docs for struct.pack(u'...') (issue #147)
1 parent 94ea646 commit 661a1c5

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

docs/stdlib_incompatibilities.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,17 @@ This enables 'ASCII mode' for regular expressions (see the docs `here
8888
struct.pack()
8989
-------------
9090

91-
The :func:`struct.pack` function must take a native string as its format argument. For example::
91+
Before Python version 2.7.7, the :func:`struct.pack` function
92+
required a native string as its format argument. For example::
9293

9394
>>> from __future__ import unicode_literals
9495
>>> from struct import pack
9596
>>> pack('<4H2I', version, rec_type, build, year, file_hist_flags, ver_can_read)
9697

97-
raises ``TypeError: Struct() argument 1 must be string, not unicode`` on Python
98-
2. To work around this, pass the format string argument as e.g.
99-
``future.utils.native('<4H2I')``.
98+
raised ``TypeError: Struct() argument 1 must be string, not unicode``.
10099

100+
This was `fixed in Python 2.7.7
101+
<https://hg.python.org/cpython/raw-file/f89216059edf/Misc/NEWS>`_.
102+
Since then, ``struct.pack()`` now also accepts unicode format
103+
strings.
101104

0 commit comments

Comments
 (0)