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


Groups > comp.lang.python > #4858

Re: string formatting

From Neil Cerutti <neilc@norwich.edu>
Newsgroups comp.lang.python
Subject Re: string formatting
Date 2011-05-06 19:54 +0000
Organization Norwich University
Message-ID <92j1v6FthtU1@mid.individual.net> (permalink)
References (1 earlier) <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <mailman.1230.1304673808.9059.python-list@python.org> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> <RTXwp.18780$Ot6.17862@newsfe15.iad>

Show all headers | View raw


On 2011-05-06, harrismh777 <harrismh777@charter.net> wrote:
> Steven D'Aprano wrote:
>> It's perfectly safe to continue using % formatting, if you
>> choose.
>
> I would hope so, since its the way in most of the books, much
> of the doc and a majority of the code...
>
> I don't really like the old style, not because there is
> anything wrong with it, because its an obvious carry-over from
> the cryptic formatting style of 'C' printf(), and others. It
> seems to me that the purpose of formatting is to make output
> clear, and therefore the output formatting style itself should
> be clear and clean.

C's printf is a venerable example of the power of notation.
Notation kicks ass. Another that's well known are regular
expressions. Python uses this powerful idea again in the struct
module. Any other places?

Functions and classes are a general purpose, though verbose, form
of notation and can be used in place of mini languages when you
don't want to bother, e.g., C++'s iostreams, and pyparsing's
grammar declarations.

Lisp declared that you could implement mini-languages in Lisp,
rather than just parsing them.

Python 3's format notation is an improvement for Python, since
Python doesn't need the type information that's crucial for C and
particularly scanf, an application of C's mini-language that
Python doesn't need. Delimiting the escape sequences also makes
it easier to read and parse complex formating declarations.

For simple constructs there's not much difference between them,
but if you switch to .format you'll probably reap some benefit.

-- 
Neil Cerutti

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


Thread

string formatting Jabba Laci <jabba.laci@gmail.com> - 2011-05-06 03:18 -0400
  Re: string formatting Web Dreamer <webdreamer@nospam.fr> - 2011-05-06 10:00 +0200
    Re: string formatting Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-06 08:46 +0000
      Re: string formatting Chris Rebert <clp2@rebertia.com> - 2011-05-06 02:23 -0700
        Re: string formatting Web Dreamer <webdreamer@nospam.fr> - 2011-05-06 14:10 +0200
          Re: string formatting nn <pruebauno@latinmail.com> - 2011-05-06 06:06 -0700
          Re: string formatting Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-06 14:33 +0000
          Re: string formatting Web Dreamer <webdreamer@nospam.fr> - 2011-05-10 16:15 +0200
            Re: string formatting Chris Angelico <rosuav@gmail.com> - 2011-05-11 00:43 +1000
        Re: string formatting Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-06 14:24 +0000
          Re: string formatting harrismh777 <harrismh777@charter.net> - 2011-05-06 14:22 -0500
            Re: string formatting harrismh777 <harrismh777@charter.net> - 2011-05-06 14:39 -0500
              Re: string formatting Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-06 13:54 -0600
              Re: string formatting Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-07 02:30 +0000
              Re: string formatting alex23 <wuwei23@gmail.com> - 2011-05-08 22:47 -0700
            Re: string formatting Neil Cerutti <neilc@norwich.edu> - 2011-05-06 19:54 +0000
            Re: string formatting Terry Reedy <tjreedy@udel.edu> - 2011-05-06 16:54 -0400
            Re: string formatting Chris Angelico <rosuav@gmail.com> - 2011-05-07 10:09 +1000
            Re: string formatting Terry Reedy <tjreedy@udel.edu> - 2011-05-07 03:55 -0400
  Re: string formatting Raymond Hettinger <python@rcn.com> - 2011-05-10 10:20 -0700

csiph-web