[Python-Dev] str and unicode (original) (raw)
M.-A. Lemburg mal at egenix.com
Wed Dec 6 10:46:34 CET 2006
- Previous message: [Python-Dev] __str__ and unicode
- Next message: [Python-Dev] __str__ and unicode
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 2006-12-06 10:26, Fredrik Lundh wrote:
over at my work copy of the python language reference, Adrian Holovaty asked about the exact semantics of the str hook:
http://effbot.org/pyref/str "The return value must be a string object." Does this mean it can be a Unicode string object? This distinction is ambiguous to me because unicode objects and string objects are both subclasses of basestring. May a str() return a Unicode object? I seem to remember earlier discussions on this topic, but don't recall when and what. From what I can tell, str may return a Unicode object, but only if can be converted to an 8-bit string using the default encoding. Is this on purpose or by accident? Do we have a plan for improving the situation in future 2.X releases ?
This was added to make the transition to all Unicode in 3k easier:
.str() may return a string or Unicode object.
.unicode() must return a Unicode object.
There is no restriction on the content of the Unicode string for .str().
-- Marc-Andre Lemburg eGenix.com
Professional Python Services directly from the Source (#1, Dec 06 2006)
Python/Zope Consulting and Support ... http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::
- Previous message: [Python-Dev] __str__ and unicode
- Next message: [Python-Dev] __str__ and unicode
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]