Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Myth Busters: % "this old style of formatting will eventually be removed from the language"

61 views
Skip to first unread message

Carlos Nepomuceno

unread,
May 21, 2013, 10:26:11 PM5/21/13
to pytho...@python.org
I was looking for something else and just found what I think is the place where I was first exposed to the myth[1]:

"Since str.format() is quite new, a lot of Python code still uses the % operator. However, because this old style of formatting will eventually be removed from the language, str.format() should generally be used."

Is this tutorial outdated or this still an issue?

[1] http://docs.python.org/2/tutorial/inputoutput.html#old-string-formatting

Ethan Furman

unread,
May 21, 2013, 10:37:32 PM5/21/13
to pytho...@python.org
On 05/21/2013 07:26 PM, Carlos Nepomuceno wrote:
> I was looking for something else and just found what I think is the place where I was first exposed to the myth[1]:
>
> "Since str.format() is quite new, a lot of Python code still uses the % operator. However, because this old style of formatting will eventually be removed from the language, str.format() should generally be used."
>
> Is this tutorial outdated or this still an issue?

It was exuberant wishful thinking. ;)

While .format() does have its uses, % is in wide-spread use even among the core-devs. It's not going away any time soon.

--
~Ethan~

Ned Batchelder

unread,
May 21, 2013, 11:26:58 PM5/21/13
to Carlos Nepomuceno, pytho...@python.org
On 5/21/2013 10:26 PM, Carlos Nepomuceno wrote:
> I was looking for something else and just found what I think is the place where I was first exposed to the myth[1]:
>
> "Since str.format() is quite new, a lot of Python code still uses the % operator. However, because this old style of formatting will eventually be removed from the language, str.format() should generally be used."
>
> Is this tutorial outdated or this still an issue?
>
> [1] http://docs.python.org/2/tutorial/inputoutput.html#old-string-formatting

That tutorial is out of date. %-formatting isn't being removed.

--Ned.

Carlos Nepomuceno

unread,
May 22, 2013, 1:59:54 AM5/22/13
to pytho...@python.org
Ok. Thanks!

bugs.python.org/issue18031

----------------------------------------
> Date: Tue, 21 May 2013 23:26:58 -0400
> From: n...@nedbatchelder.com
> To: carlosne...@outlook.com
> CC: pytho...@python.org
> Subject: Re: Myth Busters: % "this old style of formatting will eventually be removed from the language"

Skip Montanaro

unread,
May 22, 2013, 6:35:42 AM5/22/13
to Ned Batchelder, pytho...@python.org
>> Is this tutorial outdated or this still an issue?
>>
>> [1]
>> http://docs.python.org/2/tutorial/inputoutput.html#old-string-formatting
>
>
> That tutorial is out of date. %-formatting isn't being removed.

OTOH, PEP 3101 also mentions deprecation, at the very end: "... both
systems can co-exist until it comes time to deprecate the older
system."

I have been operating under the assumption since the days of that PEP
that %-style formatting would eventually disappear, dreading the day
when I'd have to learn the str.format language. I apologize for
(inadvertently) spreading FUD.

It does seem like the documentation should be updated in a few places.
If the decision has been made to not remove the older system, it
might be worthwhile to mention that somewhere. Clearly the tutorial
and PEP 3101 should be updated.

Skip

Denis McMahon

unread,
May 22, 2013, 10:24:03 AM5/22/13
to
On Tue, 21 May 2013 23:26:58 -0400, Ned Batchelder wrote:

> On 5/21/2013 10:26 PM, Carlos Nepomuceno wrote:

>> "Since str.format() is quite new, a lot of Python code still uses the %
>> operator. However, because this old style of formatting will eventually
>> be removed from the language, str.format() should generally be used."

>> Is this tutorial outdated or this still an issue?

> That tutorial is out of date. %-formatting isn't being removed.

Indeed, removing %-formatting could break a substantial amount of live
code, with potentially significant maintenance effort in the user
community simply to make existing code work with the new interpreter. The
effect of this on corporations using python code translates into
"business risk", and the next step is "we can avoid the business risk by
migrating our python scripts to some other language."

For the designers and maintainers of any language to arbitrarily[1] (in
the eyes of the user base) remove a widely used feature that would have a
major effect on the user base could kill off a language, simply because
many users will not want to take the risk of it happening again, even if
they can easily automate the upgrade from removed obsolete language
feature to new shiny language feature.

[1] Some portion of the user base will always consider any such change
that causes them headaches and additional effort as having been
arbitrary, no matter how well the language designers and maintainers
explain the need to break the old scripts.

--
Denis McMahon, denismf...@gmail.com

Terry Jan Reedy

unread,
May 22, 2013, 3:40:22 PM5/22/13
to pytho...@python.org
On 5/22/2013 10:24 AM, Denis McMahon wrote:

> Indeed, removing %-formatting could break a substantial amount of live
> code, with potentially significant maintenance effort in the user

While I would like to see % formatting go away everntually*, other
developers would not. In any case, I agree that it should not disappear
until there is a foolproof conversion tool, probably custom written. I
am working on other things.

* perhaps in 10 years?, when all 2.x code that is going to be converted
has been converted

nn

unread,
May 22, 2013, 3:49:51 PM5/22/13
to
I was of the impression that deprecating % was still planned for Py4k,
whenever that is. I personally believe that eliminating % formatting
would reduce bugs and generally make code clearer, but I realize that
breaking backward compatibility has a high price.

0 new messages