[Patches] [ python-Patches-1463370 ] Add .format() method to str and unicode

SourceForge.net noreply at sourceforge.net
Mon Apr 3 21:44:11 CEST 2006


Patches item #1463370, was opened at 2006-04-03 03:42
Message generated for change (Comment added) made by gvanrossum
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1463370&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core (C code)
Group: Python 3000
Status: Open
Resolution: None
Priority: 5
Submitted By: crutcher (crutcher_gmail)
Assigned to: Nobody/Anonymous (nobody)
Summary: Add .format() method to str and unicode

Initial Comment:
patch to add .format() method to string and unicode types.

----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2006-04-03 15:44

Message:
Logged In: YES 
user_id=6380

Let's please continue this discussion on
python-3000 at python.org instead of a random SF item.

----------------------------------------------------------------------

Comment By: M.-A. Lemburg (lemburg)
Date: 2006-04-03 15:15

Message:
Logged In: YES 
user_id=38388

I would rather like to see any non-trivial formatting be
moved into a module and have functions that operate on
strings and Unicode.

Methods on simple types shouldn't really implement any
complicated features.

Formatting is one of those things that everybody wants to
implement in different ways. Just look at the gazillion
different templating engines out there for examples :-)

Better remove the %-formatting altogether in Py3k and add a
module which implements 2.x style %-formatting as well as
pep 292 style $-formatting.


----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2006-04-03 14:44

Message:
Logged In: YES 
user_id=6380

I like this.

The reason to like this in favor of s%x was expressed by
Walter Dörwald on the python-3000 list:

"""
it avoids one problem you might run into with %:
If you have only one argument, writing ``s % (x,)``
as ``s % x`` will break when the
argument x happens to be a tuple.
You won't have this problem with
s.format(x).
"""

However, this might be our chance to introduce a new
formatting syntax, since there are many problems with the %s
style (especially %(foo)s).  See PEP 292.

We need a Python 3000 group in the trackers.

----------------------------------------------------------------------

Comment By: M.-A. Lemburg (lemburg)
Date: 2006-04-03 04:37

Message:
Logged In: YES 
user_id=38388

Why would we need a method for formatting ? We already have
the %-based formatting which can also be access via .__mod__().

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1463370&group_id=5470


More information about the Patches mailing list