[Python-Dev] Backporting PEP 3101 to 2.6
M.-A. Lemburg
mal at egenix.com
Thu Jan 10 15:07:07 CET 2008
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__(empty_string). 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, format_spec):
> return format(str(self), format_spec)
>
> In 2.6, I assume it should be the equivalent of:
>
> class object:
> def __format__(self, format_spec):
> if isinstance(format_spec, str):
> return format(str(self), format_spec)
> elif isinstance(format_spec, unicode):
> return format(unicode(self), format_spec)
> 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
More information about the Python-Dev
mailing list