Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #18382

Re: .format vs. %

References (2 earlier) <mailman.4321.1325544682.27778.python-list@python.org> <fd8933b8-0cca-4127-8f9b-38b056ee075a@h12g2000yqg.googlegroups.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <mailman.4334.1325570337.27778.python-list@python.org> <4f029d1e$0$29880$c3e8da3$5496439d@news.astraweb.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2012-01-03 01:16 -0700
Subject Re: .format vs. %
Newsgroups comp.lang.python
Message-ID <mailman.4337.1325578606.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Jan 2, 2012 at 11:15 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Which is exactly why it is not deprecated: it doesn't say it is
> deprecated and has no timeline for removal. It may not even be removed:
> "may" go away is not "will" go away.
>
> Going around saying that features are deprecated just because they may
> (or may not) some day in the distant future become deprecated is FUD. It
> simply isn't true that % formatting is deprecated: Python Dev has a
> formal process for deprecating code, and that process has not been
> applied to % and there are no plans to do so in the foreseeable future.

So it's not formally deprecated, but it is nonetheless labeled
obsolete and discouraged, or "informally deprecated" if you will.

I'm not sure it's true that "there are no plans to do so in the
foreseeable future."  According to the release notes from Python 3.0,
% formatting was supposed to be deprecated in Python 3.1.  Why that
didn't happen, I don't know.  Maybe there was a discussion on py-dev
where it was decided that % formatting would not be deprecated after
all (in which case the misleading "obsolete" note really ought to be
removed from the documentation).  Maybe that discussion has been
tabled for the time being.  Or maybe it hasn't been deprecated simply
because nobody has gotten around to actually doing it yet.

In any case the statement of obsolescence and the lack of clarity
about the feature's future is enough cause for me to avoid the
feature, although you of course are free to use it however you want.

> There is a huge code base using this feature, including the standard
> library, and Python does not arbitrarily deprecate features used by real
> code without good reason. Just because a number of Python devs want to
> encourage people to use format doesn't imply that % will go away any time
> before Python 4000.

The reason for deprecating it is because Python currently has no fewer
than three mechanisms for string formatting (not even including
ordinary string concatenation), which according to the Zen of Python
is two too many.  In my view, % formatting has a lot in common with
the print statement -- it's warty syntax that is better implemented as
a function.  In Python 3 we could have kept the print statement and
avoided breaking a feature commonly used by "real code" by adding the
print function as a supplement to the statement (probably with a
slightly different name).  But the devs went a step further and
actually removed the print statement, and IMO that was a good thing.
The same thing should be done with % formatting (although I agree on
one point, it likely won't happen before Python 4).

Cheers,
Ian

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

.format vs. % davidfx <dgeorge29ca@gmail.com> - 2011-12-31 10:19 -0800
  Re: .format vs. % Andrew Berg <bahamutzero8825@gmail.com> - 2011-12-31 12:34 -0600
  Re: .format vs. % Yaşar Arabacı <yasar11732@gmail.com> - 2011-12-31 20:34 +0200
    Re: .format vs. % davidfx <dgeorge29ca@gmail.com> - 2011-12-31 10:44 -0800
    Re: .format vs. % davidfx <dgeorge29ca@gmail.com> - 2011-12-31 10:44 -0800
      Re: .format vs. % Yaşar Arabacı <yasar11732@gmail.com> - 2011-12-31 20:51 +0200
      Re: .format vs. % Evan Driscoll <edriscoll@wisc.edu> - 2011-12-31 13:47 -0500
        Re: .format vs. % Miki Tebeka <miki.tebeka@gmail.com> - 2012-01-01 13:11 -0800
          Re: .format vs. % Terry Reedy <tjreedy@udel.edu> - 2012-01-02 05:29 -0500
        Re: .format vs. % Miki Tebeka <miki.tebeka@gmail.com> - 2012-01-01 13:11 -0800
      Re: .format vs. % Alexander Kapps <alex.kapps@web.de> - 2011-12-31 19:59 +0100
      Re: .format vs. % Tim Chase <python.list@tim.thechases.com> - 2011-12-31 13:24 -0600
      Re: .format vs. % Lie Ryan <lie.1296@gmail.com> - 2012-01-01 06:34 +1100
      Re: .format vs. % Robert Kern <robert.kern@gmail.com> - 2011-12-31 19:43 +0000
      Re: .format vs. % Terry Reedy <tjreedy@udel.edu> - 2011-12-31 16:09 -0500
  Re: .format vs. % Ethan Furman <ethan@stoneleaf.us> - 2012-01-02 14:00 -0800
    Re: .format vs. % Rick Johnson <rantingrickjohnson@gmail.com> - 2012-01-02 17:59 -0800
      Re: .format vs. % Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-03 03:52 +0000
        Re: .format vs. % Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-02 22:58 -0700
          Re: .format vs. % Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-03 06:15 +0000
            Re: .format vs. % Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-03 01:16 -0700
            Re: .format vs. % Ethan Furman <ethan@stoneleaf.us> - 2012-01-03 05:26 -0800
            Re: .format vs. % Ethan Furman <ethan@stoneleaf.us> - 2012-01-03 11:38 -0800
            Re: .format vs. % Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-01-03 15:02 -0500
            Re: .format vs. % Ethan Furman <ethan@stoneleaf.us> - 2012-01-03 12:16 -0800
        Re: .format vs. % Andrew Berg <bahamutzero8825@gmail.com> - 2012-01-03 04:55 -0600
        Re: .format vs. % Stefan Krah <stefan-usenet@bytereef.org> - 2012-01-03 12:47 +0100
          Re: .format vs. % Neil Cerutti <neilc@norwich.edu> - 2012-01-03 13:58 +0000
            Re: .format vs. % Stefan Krah <stefan-usenet@bytereef.org> - 2012-01-03 15:17 +0100
              Re: .format vs. % Neil Cerutti <neilc@norwich.edu> - 2012-01-03 15:15 +0000
                Re: .format vs. % Neil Cerutti <neilc@norwich.edu> - 2012-01-03 15:24 +0000
          Re: .format vs. % Neil Cerutti <neilc@norwich.edu> - 2012-01-03 19:46 +0000
            Re: .format vs. % Ethan Furman <ethan@stoneleaf.us> - 2012-01-03 12:00 -0800
            Re: .format vs. % Stefan Krah <stefan-usenet@bytereef.org> - 2012-01-03 21:53 +0100
        Re: .format vs. % Chris Angelico <rosuav@gmail.com> - 2012-01-04 00:04 +1100
  Re: .format vs. % Rick Johnson <rantingrickjohnson@gmail.com> - 2012-01-02 17:51 -0800
    Re: .format vs. % Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-03 03:47 +0000
  Re: .format vs. % 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-03 07:47 -0800
    Re: .format vs. % alex23 <wuwei23@gmail.com> - 2012-01-03 18:26 -0800
      Re: .format vs. % 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-04 00:25 -0800
        Re: .format vs. % alex23 <wuwei23@gmail.com> - 2012-01-04 16:23 -0800
          Re: .format vs. % 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-04 17:41 -0800

csiph-web