Re: new string-formatting preferred? (was "What is this syntax ?")

2011-06-21 Thread Tim Chase
On 06/21/2011 05:19 PM, Terry Reedy wrote: On 6/21/2011 7:33 AM, Tim Chase wrote: http://docs.python.org/library/stdtypes.html#str.format> Is there a good link to a thread-archive on when/why/how .format(...) became "preferred to the % formatting"? That is a controversial statement. I'm no

Re: new string-formatting preferred? (was "What is this syntax ?")

2011-06-21 Thread Terry Reedy
On 6/21/2011 7:33 AM, Tim Chase wrote: On 06/20/2011 09:17 PM, Terry Reedy wrote: On 6/20/2011 8:46 PM, Tim Chase wrote: On 06/20/2011 05:19 PM, Ben Finney wrote: “This method of string formatting is the new standard in Python 3.0, and should be preferred to the % formatting described in Strin

Re: new string-formatting preferred? (was "What is this syntax ?")

2011-06-21 Thread Tim Chase
On 06/20/2011 09:17 PM, Terry Reedy wrote: On 6/20/2011 8:46 PM, Tim Chase wrote: On 06/20/2011 05:19 PM, Ben Finney wrote: “This method of string formatting is the new standard in Python 3.0, and should be preferred to the % formatting described in String Formatting Operations in new code.” h

Re: new string-formatting preferred? (was "What is this syntax ?")

2011-06-20 Thread Terry Reedy
On 6/20/2011 8:46 PM, Tim Chase wrote: On 06/20/2011 05:19 PM, Ben Finney wrote: “This method of string formatting is the new standard in Python 3.0, and should be preferred to the % formatting described in String Formatting Operations in new code.” http://docs.python.org/library/stdtypes.html#

Re: new string-formatting preferred? (was "What is this syntax ?")

2011-06-20 Thread Tim Chase
On 06/20/2011 05:19 PM, Ben Finney wrote: “This method of string formatting is the new standard in Python 3.0, and should be preferred to the % formatting described in String Formatting Operations in new code.” http://docs.python.org/library/stdtypes.html#str.format> Is there a good link to a

Re: What is this syntax ?

2011-06-20 Thread Ben Finney
Claudiu Popa writes: > Hello, (Please don't top-post. Instead, interleave your responses below each quoted part you're responding to, as in this message. See also .) > Isn't this similar to php interpolation? And qu

Re: What is this syntax ?

2011-06-20 Thread Claudiu Popa
Hello, Isn't this similar to php interpolation? And quite readable imo. >>> import string >>> template = string.Template("$scheme://$host:$port/$route#$fragment") >>> template.substitute(scheme="http", host="google.com", port="80", route="", >>> fragment="") 'http://google.com:80/#' >>> Roy Sm

Re: What is this syntax ?

2011-06-19 Thread Vito 'ZeD' De Tullio
Steven D'Aprano wrote: >> and you can achieve php interpolation via locals() >> > a = 'b' > print("%(a)s" % locals()) >> b > > You can do that, but when reading code I consider any direct use of > locals() (and globals() for that matter) to be a code smell: well you're right, me neither

Re: What is this syntax ?

2011-06-19 Thread Steven D'Aprano
On Sun, 19 Jun 2011 23:06:36 +0200, Vito 'ZeD' De Tullio wrote: > well, in python3 you can use dict to format strings > print("%(a)s" % {'a':'b'}) > b It's not just Python 3. That bit of functionality goes back all the way to Python 1.5, which is the oldest version I have installed. In Py

Re: What is this syntax ?

2011-06-19 Thread Benjamin Kaplan
On Sun, Jun 19, 2011 at 2:06 PM, Vito 'ZeD' De Tullio wrote: > Roy Smith wrote: > >> There's something nice about building up strings in-line, as >> opposed to having to look somewhere to see what's being interpolated. >> To give a more complex example, consider: >> >> print "$scheme://$host:$port

Re: What is this syntax ?

2011-06-19 Thread Vito 'ZeD' De Tullio
Roy Smith wrote: > There's something nice about building up strings in-line, as > opposed to having to look somewhere to see what's being interpolated. > To give a more complex example, consider: > > print "$scheme://$host:$port/$route#$fragment" > > That certainly seems easier to me to read tha

Re: What is this syntax ?

2011-06-19 Thread Roy Smith
In article , rusi wrote: > On Jun 19, 8:39 pm, Roy Smith wrote: > > > This is one of the (very) few places PHP wins over Python.  In PHP, I > > would write this as > > > > print "'$x'" > > > You dont find > > >>> print '"%s"' % x > > readable? Why? I didn't say it wasn't readable, I said

Re: What is this syntax ?

2011-06-19 Thread rusi
On Jun 19, 8:39 pm, Roy Smith wrote: > This is one of the (very) few places PHP wins over Python.  In PHP, I > would write this as > > print "'$x'" You dont find >>> print '"%s"' % x readable? Why? -- http://mail.python.org/mailman/listinfo/python-list

Re: What is this syntax ?

2011-06-19 Thread Roy Smith
In article <4dfe10d1$0$28053$426a3...@news.free.fr>, candide wrote: > OK, thanks for your explanation, it was just stringisation ! > > > I erroneously focused on > > +x+ > > as a kind of placeholder unknown to me, instead of left and right > concatenations ;) > > It would be more readable

Re: What is this syntax ?

2011-06-19 Thread candide
OK, thanks for your explanation, it was just stringisation ! I erroneously focused on +x+ as a kind of placeholder unknown to me, instead of left and right concatenations ;) It would be more readable for me if it were edited >>> print '"' + x + '"' # better spacing "foo" >>> or with stri

Re: What is this syntax ?

2011-06-19 Thread Chris Angelico
On Sun, Jun 19, 2011 at 11:41 PM, candide wrote: > With Python 2.7 : > x="foo" print '"'+x+'"' > "foo" As Laurent posted, it's simply a literal double-quote character, enclosed in single quotes. But for making a quoted string, this isn't reliable (what if there's a double quote in

Re: What is this syntax ?

2011-06-19 Thread Noah Hall
On Sun, Jun 19, 2011 at 2:41 PM, candide wrote: > With Python 2.7 : > x="foo" print '"'+x+'"' > "foo" > What is this curious syntax on line 2 ? Where is it documented ? Just to make it clear to you what is happening - >>> x = "foo" >>> print ' " ' + x + ' " ' " foo " >>> Anyway, it'

Re: What is this syntax ?

2011-06-19 Thread Laurent Claessens
Le 19/06/2011 15:41, candide a écrit : With Python 2.7 : >>> x="foo" >>> print '"'+x+'"' "foo" >>> What is this curious syntax on line 2 ? Where is it documented ? When you want to have an explicit double quote " in a string, you put in between single quote '. (and vice versa) So

What is this syntax ?

2011-06-19 Thread candide
With Python 2.7 : >>> x="foo" >>> print '"'+x+'"' "foo" >>> What is this curious syntax on line 2 ? Where is it documented ? -- http://mail.python.org/mailman/listinfo/python-list