Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #22441
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'string.': 0.04; 'syntax': 0.04; 'result,': 0.05; 'referring': 0.07; 'be:': 0.09; 'formatting': 0.09; 'itself,': 0.09; 'subject:string': 0.09; 'cc:addr:python-list': 0.10; 'subject:python': 0.11; '>>>': 0.14; 'eval': 0.16; 'evaluating': 0.16; 'from:addr:lanyjie': 0.16; 'from:name:yingjie lan': 0.16; 'okay': 0.16; 'received:124.205': 0.16; 'reply-to:addr:lanyjie': 0.16; 'reply-to:name:yingjie lan': 0.16; 'yingjie': 0.16; 'refers': 0.17; 'string,': 0.17; 'this:': 0.17; 'string': 0.19; 'example': 0.19; 'controlled': 0.21; 'differ': 0.21; 'mechanism': 0.21; 'header:In-Reply-To:1': 0.22; 'raw': 0.23; 'variable': 0.23; 'cc:2**0': 0.26; 'realize': 0.26; 'function': 0.26; 'common': 0.28; 'cc:addr:python.org': 0.28; 'question': 0.28; 'password.': 0.28; 'strings,': 0.28; 'subject:skip:i 10': 0.28; 'reply-to:addr:yahoo.com': 0.28; "skip:' 10": 0.29; 'like:': 0.32; 'could': 0.32; 'really': 0.33; 'turn': 0.33; 'break': 0.34; 'called': 0.34; 'getting': 0.35; 'characters': 0.35; 'there': 0.36; 'another': 0.36; 'but': 0.37; 'say': 0.37; 'comments': 0.37; 'dynamic': 0.37; 'subject:: ': 0.37; 'sense': 0.37; "didn't": 0.38; 'from:': 0.38; 'under': 0.38; 'old': 0.38; 'allow': 0.40; '...': 0.40; 'said': 0.40; "won't": 0.40; 'show': 0.61; 'skip:$ 10': 0.62; 'kind': 0.63; 'back': 0.63; 'more': 0.63; 'here': 0.64; 'risk': 0.65; 'header:Reply-To:1': 0.67; 'safe': 0.68; 'below.': 0.68; 'increase': 0.70; "'it": 0.84; 'calls,': 0.84; 'distinguish': 0.84; 'hood': 0.84; 'hunt': 0.84; 'received:98.138.90.51': 0.84; 'received:98.138.91.35': 0.84; 'received:nm28-vm1.bullet.mail.ne1.yahoo.com': 0.84; 'proposal,': 0.91; 'received:98.138.226': 0.91; 'to:addr:hotmail.com': 0.98 |
| X-Yahoo-Newman-Property | ymail-3 |
| X-Yahoo-Newman-Id | 148483.94051.bm@omp1063.mail.ne1.yahoo.com |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1333351461; bh=+OrMeSFXIiU3y8sQqKTgFR4it4mUtwn46xmAb5/my70=; h=X-YMail-OSG:Received:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=YCvju1EadLgYdc0p8mbVs+YJ+cyQAI7TSqTGtYy5weHiA/sTaaEnVe6vZj9EI7CdJmgrJNiIOwFJPbbZElctzGGTBMDhN/YGIJQXQ+KVopwwq9RSPgRv+bVC3TYiKYTYIpn3h6ll6BoGZy5rgQiqqqZ4osklH+I2/DazeGrI3LE= |
| 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:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=iniP1YEElEi3L+u1dRFIJFpxHj+QOgMKiQSognUF7kdw5ZIShSm6C+dPR3641WB1c0VkTho2hHYMARGclzCOWcMs4Km7ETNvSOGdILgo/5ylS/nK9gXX1t1gU6o8+ywn/A80K2EuTYHOOxNrjPrMKNckn5zIbYfuD0gukSzTsqM=; |
| X-YMail-OSG | lkqutuYVM1njZ7RlQ5gauLlJLYCfvpPo28f.ol0R4VYlE9F M9h9ivV3uEEBo4zpMSnMbIMVlJDgyeIDhbupFQWcTgVVj.Cfmy10O7eFCbsz HxCKBscKtol9IhKMlX9UAT7IVHNGq4Mby9rxnFVNr8DA3sXCfVAc1Jt1Me11 8XW2g2m4BWtS486158e1vh.K3Ca12..TJLWgZHlJCidWr9vPGHmu4YQGoJSo EEBpiaM2A2mltVPhxWKAttxTlUgQbNZwv3B2Y3Vi1177SQAI2rL6rYsIVXBq 2hRb0GGPA3QJXbtJntNv3b0GVxStaGTgr5Jc41YBK14VfEX8.BJP6yS37VdN Stp5i71vTizjkQeowmoPv7ZlZr5SsGbFP.h8S3.7WySpUOpb1mqWLbd7MG3G znHt9C7S6Ko8_X0pIrRmixBfM.nRXegaYy0qY_LQjFQzpJ.xp6l9cZYolPAG Ebi16hLZ2O10o4H2ORZT2dDU- |
| X-Mailer | YahooMailWebService/0.8.117.340979 |
| References | <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <BLU155-W48CDC5464B3B0ACA78E35C894E0@phx.gbl> |
| Date | Mon, 2 Apr 2012 00:24:21 -0700 (PDT) |
| From | Yingjie Lan <lanyjie@yahoo.com> |
| Subject | Re: string interpolation for python |
| To | Adrian Hunt <cyborgv2@hotmail.com> |
| In-Reply-To | <BLU155-W48CDC5464B3B0ACA78E35C894E0@phx.gbl> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list <python-list@python.org> |
| 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.1198.1333351470.3037.python-list@python.org> (permalink) |
| Lines | 29 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1333351470 news.xs4all.nl 6960 [2001:888:2000:d::a6]:39380 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:22441 |
Show key headers only | View raw
Hi Adrian, see my comments below.
>________________________________
> From: Adrian Hunt <cyborgv2@hotmail.com>
...
>It could break old code... okay you may say you should’nt allow
>certain characters but if they're printable and used in a controlled
>environment those characters can dramatically increase the security
>of a username and password.
What you said makes lots of sense to me.
if strings are interpolated *automatically*.
But it won't and shouldn't.
They are called "Dynamic strings".
Dynamic strings can achieve formatting,
but the mechanism under the hood differ
from common strings dramatically.
Many here didn't realize that this is not
another formatting proposal, it is a new
kind of *expression*.
To have it in Python, we will need
a new kind of syntax to distinguish it
from other strings, such as raw strings
and the like. A raw string looks like:
>>> r'my\\ raw str'
'my\\\\ raw str'
A dynamic string may look like this:
>>> name = "Peter" #common string
>>> d"Thank you, $name$!" #dynamic string!
'Thank you, Peter!'
The following example would make it feel
a lot more safe (suppose a = raw_input()):
>>> a = 'd"Are you $name$?"'
>>> print(a)
'd"Are you $name$?"'
>>> eval('d"Are you $name$?"')
'Are you Peter?'
>>> d"It contains $len(_.split())$ words!"
'It contains 3 words!'
An interesting question might be:
what if a dynamic string is referring
to another dynamic string, which
in turn refers back to the former?
The answer is: no variable can hold
a dynamic string itself, only its result,
which can only be a common string.
However, a infinite recursion may
occur if the eval function is used inside:
>>> a = 'd"$eval(a)$"'
>>> eval(a)
This is just to show a dynamic string
is really an expression in disguise.
Like evaluating any expression containing
function calls, there is risk of getting into
infinite recursion.
Cheers,
Yingjie
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 00:24 -0700
csiph-web