[docs] python 3 library reference

Alvaro De Amicis alv.deamicis at gmail.com
Wed May 30 15:53:42 CEST 2012


I think there is an inaccurate information in Python 3 documentation.
In the 'Library Reference', chapter 4 'Built-in Types', there is a
description of string methods (par. 4.6.1).
Among them, there is the 'encode' method:

...
str.encode(encoding="utf-8", errors="strict")
Return an encoded version of the string as a bytes object. Default
encoding is 'utf-8'. errors may be given to set a different error
handling scheme. The default for errors is 'strict', meaning that
encoding errors raise a UnicodeError. Other possible values are
'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' and any
other name registered via codecs.register_error(), see section Codec
Base Classes. For a list of possible encodings, see section Standard
Encodings.

Changed in version 3.1: Support for keyword arguments added.
...

But I think that the support for keyword arguments was added in 3.2!

In fact I got this exception:
----------------------------------------------------------------------------------------------------
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.1/tkinter/__init__.py", line 1402, in __call__
    return self.func(*args)
  File "./stabtk-120530.py", line 510, in <lambda>
    Button(wnd, text='Salva...', width=16, command=(lambda:
g_salva(var, wnd, True, ''))).pack(pady=1)
  File "./stabtk-120530.py", line 497, in g_salva
    fp.write(txt.encode(encoding="utf-8", errors="strict"))
TypeError: encode() takes no keyword arguments
----------------------------------------------------------------------------------------------------
I ran this script with Python 3.1.2 (r312:79147, Dec 9 2011, 20:47:34)
[GCC 4.4.3] on linux2

If I run the same script with Python 3.2, I don't get any error!

Am I wrong, or is the reference wrong?

Thank you


A. De Amicis


More information about the docs mailing list