[Python-Dev] Backporting PEP 3101 to 2.6 (original) (raw)
M.-A. Lemburg mal at egenix.com
Thu Jan 10 15:07:07 CET 2008
- Previous message: [Python-Dev] Backporting PEP 3101 to 2.6
- Next message: [Python-Dev] Backporting PEP 3101 to 2.6
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 2008-01-10 14:31, Eric Smith wrote:
(I'm posting to python-dev, because this isn't strictly 3.0 related. Hopefully most people read it in addition to python-3000).
I'm working on backporting the changes I made for PEP 3101 (Advanced String Formatting) to the trunk, in order to meet the pre-PyCon release date for 2.6a1. I have a few questions about how I should handle str/unicode. 3.0 was pretty easy, because everything was unicode.
Since this is a new feature, why bother with strings at all (even in 2.6) ?
Use Unicode throughout and be done with it.
1: How should the builtin format() work? It takes 2 parameters, an object o and a string s, and returns o.format(s). If s is None, it returns o.format(emptystring). In 3.0, the empty string is of course unicode. For 2.6, should I use u'' or ''?
2: In 3.0, object.format() is essentially this: class object: def format(self, formatspec): return format(str(self), formatspec) In 2.6, I assume it should be the equivalent of: class object: def format(self, formatspec): if isinstance(formatspec, str): return format(str(self), formatspec) elif isinstance(formatspec, unicode): return format(unicode(self), formatspec) else: error Does that seem right? 3: Every overridden format() method is going to have to check for _string or unicode, just like object.format() does, and return either a string or unicode object, appropriately. I don't see any way around this, but I'd like to hear any thoughts. I guess there aren't all that many format methods that will be implemented, so this might not be a big burden. I'll of course implement the built in ones. Thanks in advance for any insights.
-- Marc-Andre Lemburg eGenix.com
Professional Python Services directly from the Source (#1, Jan 10 2008)
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,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611
- Previous message: [Python-Dev] Backporting PEP 3101 to 2.6
- Next message: [Python-Dev] Backporting PEP 3101 to 2.6
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]