New submission from Nick Coghlan:

The codecs module has long offered encode() and decode() convenience functions 
(since 2004: http://hg.python.org/cpython-fullhistory/rev/8ea2cb1ec598), but 
they're not documented (except through docstrings). We should fix that.

>From the docstrings:
==========
encode(obj, [encoding[,errors]]) -> object

Encodes obj using the codec registered for encoding. encoding defaults
to the default encoding. errors may be given to set a different error
handling scheme. Default is 'strict' meaning that encoding errors raise
a ValueError. Other possible values are 'ignore', 'replace' and
'xmlcharrefreplace' as well as any other name registered with
codecs.register_error that can handle ValueErrors.
==========
decode(obj, [encoding[,errors]]) -> object

Decodes obj using the codec registered for encoding. encoding defaults
to the default encoding. errors may be given to set a different error
handling scheme. Default is 'strict' meaning that encoding errors raise
a ValueError. Other possible values are 'ignore' and 'replace'
as well as any other name registered with codecs.register_error that is
able to handle ValueErrors.
==========

Note that the difference between the convenience functions in the codecs module 
and the methods on str, bytes and bytearray is that the latter have additional 
type checks to limit their usage to text encodings. str.encode expects a 
str->bytes conversion, while bytes.decode and bytearray.decode both expect the 
codec to produce a str object. codecs.encode and codecs.decode are both 
arbitrary object->object conversions, limited only by whatever the chosen codec 
supports.

----------
assignee: docs@python
components: Documentation
messages: 187700
nosy: docs@python, ncoghlan
priority: normal
severity: normal
status: open
title: Document codecs.encode and codecs.decode
versions: Python 2.7, Python 3.3, Python 3.4

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue17827>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to