Title: Add .format() method to str and unicode
Type: Stage:
Components: Interpreter Core Versions: Python 3.0
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: crutcher_gmail, gvanrossum, lemburg
Priority: normal Keywords: patch

Created on 2006-04-03 07:42 by crutcher_gmail, last changed 2008-01-06 22:29 by admin. This issue is now closed.

File name Uploaded Description Edit
format.diff crutcher_gmail, 2006-04-03 07:42 patch to add .format() to str and unicode
Messages (5)
msg49949 - (view) Author: crutcher (crutcher_gmail) Date: 2006-04-03 07:42
patch to add .format() method to string and unicode types.
msg49950 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2006-04-03 08:37
Logged In: YES 

Why would we need a method for formatting ? We already have
the %-based formatting which can also be access via .__mod__().
msg49951 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2006-04-03 18:44
Logged In: YES 

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

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.
msg49952 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2006-04-03 19:15
Logged In: YES 

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.
msg49953 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2006-04-03 19:44
Logged In: YES 

Let's please continue this discussion on instead of a random SF item.
Date User Action Args
2008-01-06 22:29:46adminsetkeywords: - py3k
versions: Python 3.0
2007-08-30 16:37:21loewissetversions: + Python 3.0
2006-04-03 07:42:31crutcher_gmailcreate