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


Groups > comp.lang.python > #22459

Re: string interpolation for python

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed10.multikabel.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <lanyjie@yahoo.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'anyway.': 0.05; 'issue,': 0.05; 'things.': 0.05; 'assignment': 0.07; 'correct.': 0.07; 'expressions': 0.07; 'new,': 0.07; 'ok.': 0.07; 'python': 0.09; '>>>>': 0.09; 'computed': 0.09; 'formatting': 0.09; 'subject:string': 0.09; 'sure,': 0.09; 'type,': 0.09; 'subject:python': 0.11; 'equivalent': 0.12; 'itself.': 0.12; '>>>': 0.14; 'to:name:python-list@python.org': 0.14; '"are': 0.16; '"well,': 0.16; '(and,': 0.16; 'eval': 0.16; 'expressions,': 0.16; 'expressions.': 0.16; 'from:addr:lanyjie': 0.16; 'from:name:yingjie lan': 0.16; 'magic': 0.16; 'need:': 0.16; 'notation,': 0.16; 'perfect.': 0.16; 'received:124.205': 0.16; 'reply-to:addr:lanyjie': 0.16; 'reply-to:name:yingjie lan': 0.16; 'substitute': 0.16; 'syntactic': 0.16; 'syntax,': 0.16; 'yingjie': 0.16; 'comparing': 0.17; 'string,': 0.17; 'allows': 0.20; 'latter': 0.21; 'skip:% 10': 0.21; 'header:In-Reply-To:1': 0.22; 'demonstrate': 0.23; 'issue.': 0.23; 'hey': 0.23; 'cheers,': 0.26; 'realize': 0.26; 'sequence': 0.27; 'concern': 0.28; 'now?': 0.28; 'proposing': 0.28; 'subject:skip:i 10': 0.28; 'all.': 0.28; 'reply-to:addr:yahoo.com': 0.28; 'especially': 0.28; 'supported': 0.30; 'skip:b 20': 0.30; 'knows': 0.31; 'massive': 0.34; 'to:addr :python-list': 0.35; 'things': 0.35; 'there': 0.36; 'does': 0.36; 'another': 0.36; '(with': 0.36; 'languages': 0.36; 'being': 0.36; 'but': 0.37; 'community': 0.37; 'far': 0.37; 'say': 0.37; 'why': 0.37; 'dynamic': 0.37; 'subject:: ': 0.37; 'issues': 0.38; 'old': 0.38; 'to:addr:python.org': 0.39; 'sure': 0.40; 'allow': 0.40; '8bit%:8': 0.40; 'quite': 0.40; "won't": 0.40; 'more.': 0.61; 'evaluate': 0.62; 'is.': 0.62; 'more': 0.63; 'header:Reply-To:1': 0.67; 'friendly': 0.68; 'business.': 0.79; 'absolutely': 0.84; ':).': 0.84; 'defensive': 0.84; 'differences,': 0.84; 'everything.': 0.84; 'hostile': 0.84; 'personally.': 0.84; 'spite': 0.84; 'careful': 0.91; 'received:98.138.90.53': 0.91
X-Yahoo-Newman-Property ymail-3
X-Yahoo-Newman-Id 608768.58754.bm@omp1048.mail.ne1.yahoo.com
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1333367201; bh=VwwbkidIuqWdLMIif7Fo0PkIieomaVJJiG3fuSRjXrg=; h=X-YMail-OSG:Received:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=OrtEy2JK85+zr7Rp4cNO0HHhvx1TZkn1ITfVfgaP2JggRf7ezMVo69tWr9e4MeX1MCMA0pmwavLEphpoPiygLZmW83qTI9WBVMigoHSJdLLoNVDvHlmzhMH02Z62HzlTWe3rZDodr+bqft91xoTCJ+IDv/OPWEMXygzWllvY3bg=
DomainKey-Signature a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=O/dNgRcGVLDCAvIdSPrzWsSZy2qyZUKvPZexDBDGoHjK93MZIiysjSNmNRda4cFaWhohGPdlpmhIQgJXOJzmOkNIzV7UJoNWCRCQ2216uNCFTGQwbYx/nRJhbpsA5DdONIJu+mexQ1WxZI4aDt7HLPh/teB0JdoY/xArotVlU8A=;
X-YMail-OSG KXUWadIVM1kwlZ8F1i8bxpBL69owpa9qLvsC5NpzUJW.kdG 9Cddam13i1175XCFRe2918IF8S8PGDoBr7t4HZup9Ccj9lxOH_uyqGvBEKtJ KjHkyjQ3pG5qPDMerRXy_nYpjX9CxDJGVPS5xDZ7rHNvyISGi5khZmVZwslt LQBpqPwd8QRl_Iop82nGjRvk6Tw8E7Bey5ss_3rmWkjW36FVtCFpxuiVCCl2 hwgVkYkNj3sQQMujIq1rtoOF2.bT9HKgjFjHpt5gjsw4nOrT0ipEbix7qfjJ 5B52ooxrx1c0Y7psAKV3BVzpZ9BQTkHApkJ7TAW5foWZrhCApBfW2gcZgv1v Whrl8DUWCZ1v2okKPouXKmmTWN.jt2VYllmZsuDnCh8BWk6GfYCPQjskOZ3J ldBlwzVxCVaad7G0ig40eyMhsaYAy4jpx4S_M84f.CDQ6MugOjKzOw_AcH3b VEdvcjLgE0HgHqrp.nXIsxA0-
X-Mailer YahooMailWebService/0.8.117.340979
References <CABgq=FyhR+Ldujj3YKRBpVXRVoeoayuXZviUUcNx-gXnFiHLSw@mail.gmail.com> <CACoeR0xV=28j6rFHm1ep3gzH9C0sbDqyxRRwX-JrVm3G+rrXww@mail.gmail.com> <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <jl6ma0$ptg$1@dough.gmane.org> <mailman.1200.1333352587.3037.python-list@python.org> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <1333357906.6147.YahooMailNeo@web121503.mail.ne1.yahoo.com> <CAPTjJmqtMhS8jp3D+SNiOAp-v9QzP5tkQzCqmO_Re7oLepOWwQ@mail.gmail.com>
Date Mon, 2 Apr 2012 04:46:41 -0700 (PDT)
From Yingjie Lan <lanyjie@yahoo.com>
Subject Re: string interpolation for python
To "python-list@python.org" <python-list@python.org>
In-Reply-To <CAPTjJmqtMhS8jp3D+SNiOAp-v9QzP5tkQzCqmO_Re7oLepOWwQ@mail.gmail.com>
MIME-Version 1.0
Content-Type text/plain; charset=iso-8859-1
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To Yingjie Lan <lanyjie@yahoo.com>
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1210.1333367209.3037.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1333367209 news.xs4all.nl 6920 [2001:888:2000:d::a6]:55752
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:22459

Show key headers only | View raw


> 

>>>>  "Are you "+name+"?"
> 
> That allows arbitrary expressions and everything.
> 

To make that work for any type, you need:

>>> "Are you "+ str(name) + "?"

Another concern is performance.

You are absolutely right, they are 
equivalent in that both are expressions.
As long as people start to realize that
dynamic strings are expressions,
there is no magic in it any more.

And allowing expressions in those
dynamic strings would make sense 
since they are of the same sort.

>>> d"sin($x$) = $ sin(x):0.3f $"

is equivalent to the expression of

>>> "sin(%s"%x + ")= %0.3f"%sin(x)

Comparing th e two, I would say the latter
is more computer friendly while 
the former, more human friendly.

If the computed result is only to be
used in formatting the string, it would
be nice to save an assignment stmt.


>> 
>>  Almost as terse, but not as readable, especially
>>  when there are many parts to substitute --
>>  the coder and reader need to be careful
>>  to make sure the sequence is correct.
> 
> I quite like this notation, personally. It's convenient, and is
> supported (with variants) in quite a few C-derived languages (and, in
> spite of the massive syntactic differences, Python does have C
> heritage).

Sure, once you get used to it, it would be harder to stop it
 the harder it is :). That's part of human nature, anyway.


>>  Why the Python community is so
>>  hostile to new things now?
>>  Python has merits,
>>  but it is far from being perfect.
> 
> Hey now, no need to get defensive :) Thing is, it's up to you to
> demonstrate that your proposal justifies itself. You're proposing to
> create a massive backward-compatibility issue, so you need to prove
> that your new way of formatting strings is sufficiently awesome to be
> able to say "Well, you need Python 3.4+ to use this".
> 


OK. I have put it out as is. I trust people knows good things.

I would simply say: this new way is much more simple 
and much more powerful. And there is no security issues
as long as you don't use the evil eval to evaluate expressions,
which is always a security issue.

It is new, and has no compatibility issues with old ways at all.
In syntax, all you need is to allow d"...", which clearly won't
affect any old ways of business.

Cheers,

Yingjie

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


Thread

Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 00:39 -0700
  Re: string interpolation for python Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-04-02 11:01 +0300
  Re: string interpolation for python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-04-02 08:26 +0000
    Re: string interpolation for python Chris Angelico <rosuav@gmail.com> - 2012-04-02 18:47 +1000
    Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 02:11 -0700
      Re: string interpolation for python Duncan Booth <duncan.booth@invalid.invalid> - 2012-04-02 10:19 +0000
      Re: string interpolation for python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-04-02 11:54 +0000
        Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 05:40 -0700
          Re: string interpolation for python Laurent Claessens <moky.math@gmail.com> - 2012-04-02 15:02 +0200
            Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 07:25 -0700
            Re: Re: string interpolation for python Evan Driscoll <driscoll@cs.wisc.edu> - 2012-04-02 15:36 -0500
          Re: string interpolation for python mwilson@the-wire.com - 2012-04-02 10:46 -0400
            Re: string interpolation for python mwilson@the-wire.com - 2012-04-02 11:34 -0400
              Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 09:02 -0700
      Re: string interpolation for python rusi <rustompmody@gmail.com> - 2012-04-02 06:04 -0700
    Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 02:17 -0700
      Re: string interpolation for python alex23 <wuwei23@gmail.com> - 2012-04-02 22:47 -0700
    Re: string interpolation for python Chris Angelico <rosuav@gmail.com> - 2012-04-02 19:56 +1000
    Re: string interpolation for python Chris Rebert <clp2@rebertia.com> - 2012-04-02 03:23 -0700
    Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 04:46 -0700
    Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 05:00 -0700
    Re: string interpolation for python Chris Angelico <rosuav@gmail.com> - 2012-04-03 00:58 +1000
      Re: string interpolation for python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-04-02 18:56 +0000
    Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 08:49 -0700
    Re: string interpolation for python Chris Angelico <rosuav@gmail.com> - 2012-04-03 08:38 +1000
      Re: string interpolation for python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-04-02 23:18 +0000
    Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 18:57 -0700

csiph-web