Re: .format vs. %

2012-01-04 Thread 88888 Dihedral
alex23於 2012年1月4日星期三UTC+8上午10時26分35秒寫道: 8 Dihedral dihedr...@googlemail.com wrote: This is a good evolution in Python. It is 2012 now and the text I/O part is not as important as 10 years ago. The next move of Python could be easy integration of C++ libraries. You mean like with

Re: .format vs. %

2012-01-04 Thread alex23
On Jan 4, 6:25 pm, 8 Dihedral dihedral88...@googlemail.com wrote: And what are you contributing to the situation other than misinformation and markov-generated spam? Do you know what can attract newbies to support python? I'm sure other people doing all the work for them would be a

Re: .format vs. %

2012-01-04 Thread 88888 Dihedral
alex23於 2012年1月5日星期四UTC+8上午8時23分06秒寫道: On Jan 4, 6:25 pm, 8 Dihedral dihedr...@googlemail.com wrote: And what are you contributing to the situation other than misinformation and markov-generated spam? Do you know what can attract newbies to support python? I'm sure other people

Re: .format vs. %

2012-01-03 Thread Ian Kelly
On Mon, Jan 2, 2012 at 11:15 PM, Steven D'Aprano steve+comp.lang.pyt...@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

Re: .format vs. %

2012-01-03 Thread Andrew Berg
On 1/2/2012 11:58 PM, Ian Kelly wrote: I can't believe I'm taking Rick's side here, but the docs do say: Note: The formatting operations described here are obsolete and may go away in future versions of Python. Use the new String Formatting in new code.

Re: .format vs. %

2012-01-03 Thread Stefan Krah
Andrew Berg bahamutzero8...@gmail.com wrote: To add my opinion on it, I find format() much more readable and easier to understand (with the exception of the {} {} {} {} syntax), and would love to see %-style formatting phased out. For me the %-style is much more readable. Also, it is

Re: .format vs. %

2012-01-03 Thread Chris Angelico
On Tue, Jan 3, 2012 at 10:47 PM, Stefan Krah stefan-use...@bytereef.org wrote: For me the %-style is much more readable. It's also very similar to C's printf, which means it's similar to everything else that's similar to printf. That makes it instantly grokkable to many many people, which is a

Re: .format vs. %

2012-01-03 Thread Ethan Furman
Ian Kelly wrote: 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. Eric Smith wrote (from a thread on pydev in 02-2011): The last thread on this I have a

Re: .format vs. %

2012-01-03 Thread Neil Cerutti
On 2012-01-03, Stefan Krah stefan-use...@bytereef.org wrote: Andrew Berg bahamutzero8...@gmail.com wrote: To add my opinion on it, I find format() much more readable and easier to understand (with the exception of the {} {} {} {} syntax), and would love to see %-style formatting phased out.

Re: .format vs. %

2012-01-03 Thread Stefan Krah
Neil Cerutti ne...@norwich.edu wrote: In the real-world telco benchmark for _decimal, replacing the single line outfil.write(%s\n % t) with outfil.write({}\n.format(t)) adds 23% to the runtime. I think %-style formatting should not be deprecated at all. When it

Re: .format vs. %

2012-01-03 Thread Neil Cerutti
On 2012-01-03, Stefan Krah stefan-use...@bytereef.org wrote: Neil Cerutti ne...@norwich.edu wrote: In the real-world telco benchmark for _decimal, replacing the single line outfil.write(%s\n % t) with outfil.write({}\n.format(t)) adds 23% to the runtime. I think

Re: .format vs. %

2012-01-03 Thread Neil Cerutti
On 2012-01-03, Neil Cerutti ne...@norwich.edu wrote: On 2012-01-03, Stefan Krah stefan-use...@bytereef.org wrote: Neil Cerutti ne...@norwich.edu wrote: In the real-world telco benchmark for _decimal, replacing the single line outfil.write(%s\n % t) with

Re: .format vs. %

2012-01-03 Thread 88888 Dihedral
davidfx於 2012年1月1日星期日UTC+8上午2時19分34秒寫道: Hello everyone, I just have a quick question about .format and %r %s %d. Should we always be using .format() for formatting strings or %? Example a = 'apples' print I love {0}..format(a) If I wanted to put .format into a variable,

Re: .format vs. %

2012-01-03 Thread Ian Kelly
On Jan 3, 2012 6:55 AM, Ethan Furman et...@stoneleaf.us wrote: Ian Kelly wrote: 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. Eric Smith wrote

Re: .format vs. %

2012-01-03 Thread Neil Cerutti
On 2012-01-03, Stefan Krah stefan-use...@bytereef.org wrote: Andrew Berg bahamutzero8...@gmail.com wrote: To add my opinion on it, I find format() much more readable and easier to understand (with the exception of the {} {} {} {} syntax), and would love to see %-style formatting phased out.

Re: .format vs. %

2012-01-03 Thread Ethan Furman
Ian Kelly wrote: http://mail.python.org/pipermail/python-dev/2009-September/092399.html Thanks, that link is very informative. Here's the link to the last discussion last February: http://mail.python.org/pipermail/python-dev/2011-February/108155.html ~Ethan~ --

Re: .format vs. %

2012-01-03 Thread Devin Jeanpierre
one obvious way != only one way Which way is the obvious way? Why is it obvious? For me, sprintf-formatting is obviously easier to use (less typing) unless you're pulling values from a dictionary or object, or already have all the variables stored in a dict you can pass in with **d. -- Devin

Re: .format vs. %

2012-01-03 Thread Joshua Landau
On 3 January 2012 19:46, Neil Cerutti ne...@norwich.edu wrote: On 2012-01-03, Stefan Krah stefan-use...@bytereef.org wrote: Andrew Berg bahamutzero8...@gmail.com wrote: To add my opinion on it, I find format() much more readable and easier to understand (with the exception of the {} {} {}

Re: .format vs. %

2012-01-03 Thread Ethan Furman
Devin Jeanpierre wrote: one obvious way != only one way Which way is the obvious way? Why is it obvious? Apparently, %-style is obvious to C and similar coders, while {}-style is obvious to Java and similar coders. :) ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list

Re: .format vs. %

2012-01-03 Thread Ethan Furman
Neil Cerutti wrote: On 2012-01-03, Stefan Krah stefan-use...@bytereef.org wrote: Andrew Berg bahamutzero8...@gmail.com wrote: To add my opinion on it, I find format() much more readable and easier to understand (with the exception of the {} {} {} {} syntax), and would love to see %-style

Re: .format vs. %

2012-01-03 Thread Stefan Krah
Neil Cerutti ne...@norwich.edu wrote: On 2012-01-03, Stefan Krah stefan-use...@bytereef.org wrote: $ ./python -m timeit -n 100 '%s % 7.928137192' 100 loops, best of 3: 0.0164 usec per loop % is faster, but not by an order of magnitude. On my machine: C:\WINDOWSpython -m

Re: .format vs. %

2012-01-03 Thread alex23
8 Dihedral dihedral88...@googlemail.com wrote: This is a good evolution in Python. It is 2012 now and the text I/O part is not as important as 10 years ago. The next move of Python could be easy integration of C++ libraries. You mean like with Py++? http://pypi.python.org/pypi/pyplusplus/

Re: .format vs. %

2012-01-02 Thread Terry Reedy
On 1/1/2012 4:11 PM, Miki Tebeka wrote: s = {0} {1} {2} {3} s.format(1, 2, 3, 4) '1 2 3 4' Or even In [4]: fmt = '{0} {1} {2} {3}'.format In [5]: print(fmt(1, 2, 3, 4)) 1 2 3 4 I have done this, except for using a more informative name, like 'emsg' for error message.

Re: .format vs. %

2012-01-02 Thread Ethan Furman
Andrew Berg wrote: On 12/31/2011 12:19 PM, davidfx wrote: Should we always be using .format() for formatting strings or %? %-style formatting will eventually go away, but probably not for a long time. %-style formatting isn't going away. ~Ethan~ --

Re: .format vs. %

2012-01-02 Thread Rick Johnson
On Jan 2, 4:00 pm, Ethan Furman et...@stoneleaf.us wrote: %-style formatting isn't going away. You may want to freshen up on the definition of deprecation. If it was NOT going away, why the need to deprecate it? hmm? It would be more beneficial if you DO NOT encourage continued usage of this

Re: .format vs. %

2012-01-02 Thread Rick Johnson
On Dec 31 2011, 12:19 pm, davidfx dgeorge2...@gmail.com wrote: Hello everyone, I just have a quick question about .format and %r %s %d. Should we always be using .format() for formatting strings or %? ALWAYS use the format method over the old and dumpy string interpolation. Why? Well because

Re: .format vs. %

2012-01-02 Thread Steven D'Aprano
On Mon, 02 Jan 2012 17:51:48 -0800, Rick Johnson wrote: You may find the format spec to be cryptic at first. Well, most find regexes cryptic also -- but would anyone recommend NOT using regexes just because of crypti-ness? I think not. It's a non-starter. I would. If you have a task that

Re: .format vs. %

2012-01-02 Thread Steven D'Aprano
On Mon, 02 Jan 2012 17:59:43 -0800, Rick Johnson wrote: On Jan 2, 4:00 pm, Ethan Furman et...@stoneleaf.us wrote: %-style formatting isn't going away. You may want to freshen up on the definition of deprecation. I'm sure Ethan knows the definition of deprecation. I'm sure he also knows

Re: .format vs. %

2012-01-02 Thread Ian Kelly
On Mon, Jan 2, 2012 at 8:52 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Mon, 02 Jan 2012 17:59:43 -0800, Rick Johnson wrote: On Jan 2, 4:00 pm, Ethan Furman et...@stoneleaf.us wrote: %-style formatting isn't going away. You may want to freshen up on the definition of

Re: .format vs. %

2012-01-02 Thread Steven D'Aprano
On Mon, 02 Jan 2012 22:58:23 -0700, Ian Kelly wrote: On Mon, Jan 2, 2012 at 8:52 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Mon, 02 Jan 2012 17:59:43 -0800, Rick Johnson wrote: On Jan 2, 4:00 pm, Ethan Furman et...@stoneleaf.us wrote: %-style formatting isn't going

Re: .format vs. %

2012-01-01 Thread Miki Tebeka
s = {0} {1} {2} {3} s.format(1, 2, 3, 4) '1 2 3 4' Or even In [4]: fmt = '{0} {1} {2} {3}'.format In [5]: print(fmt(1, 2, 3, 4)) 1 2 3 4 -- http://mail.python.org/mailman/listinfo/python-list

Re: .format vs. %

2011-12-31 Thread Andrew Berg
On 12/31/2011 12:19 PM, davidfx wrote: Should we always be using .format() for formatting strings or %? In new code, yes. %-style formatting will eventually go away, but probably not for a long time. If I wanted to put .format into a variable, how would I do that. What do you mean? -- CPython

Re: .format vs. %

2011-12-31 Thread Yaşar Arabacı
What exactly do you mean by putting .format into a variable? You mean like this: {name} is very {adj} {gender}.format(name=sandy,adj=diligent,gender=female) Sat, 31 Dec 2011 20:19:34 +0200 tarihinde davidfx dgeorge2...@gmail.com şöyle yazmış: Hello everyone, I just have a quick

Re: .format vs. %

2011-12-31 Thread davidfx
Thanks for your response. I know the following code is not going to be correct but I want to show you what I was thinking. formatter = %r %r %r %r print formatter % (1, 2, 3, 4) What is the .format version of this concept? -- http://mail.python.org/mailman/listinfo/python-list

Re: .format vs. %

2011-12-31 Thread Yaşar Arabacı
You mean like this? === a = I like {name} a.format(name=myself) 'I like myself' Sat, 31 Dec 2011 20:44:08 +0200 tarihinde davidfx dgeorge2...@gmail.com şöyle yazmış: Thanks for your response. I know the following code is not going to be

Re: .format vs. %

2011-12-31 Thread Evan Driscoll
How 'bout just: s = {0} {1} {2} {3} s.format(1, 2, 3, 4) '1 2 3 4' Evan On 12/31/2011 13:44, davidfx wrote: Thanks for your response. I know the following code is not going to be correct but I want to show you what I was thinking. formatter = %r %r %r %r print formatter % (1, 2, 3,

Re: .format vs. %

2011-12-31 Thread Benjamin Kaplan
On Dec 31, 2011 1:46 PM, davidfx dgeorge2...@gmail.com wrote: Thanks for your response. I know the following code is not going to be correct but I want to show you what I was thinking. formatter = %r %r %r %r print formatter % (1, 2, 3, 4) What is the .format version of this concept?

Re: .format vs. %

2011-12-31 Thread Alexander Kapps
On 31.12.2011 19:44, davidfx wrote: Thanks for your response. I know the following code is not going to be correct but I want to show you what I was thinking. formatter = %r %r %r %r print formatter % (1, 2, 3, 4) What is the .format version of this concept? formatter = {0} {1} {2} {3}

Re: .format vs. %

2011-12-31 Thread Tim Chase
On 12/31/11 12:57, Benjamin Kaplan wrote: format is a method of the string class. You store the string the same way you would any other. formatter = Hello, {} print(formatter.format(world)) Just to note that this syntax doesn't quite work in some earlier versions (tested below in 2.6, which

Re: .format vs. %

2011-12-31 Thread Lie Ryan
On 01/01/2012 05:44 AM, davidfx wrote: Thanks for your response. I know the following code is not going to be correct but I want to show you what I was thinking. formatter = %r %r %r %r print formatter % (1, 2, 3, 4) What is the .format version of this concept? I don't think the

Re: .format vs. %

2011-12-31 Thread Robert Kern
On 12/31/11 7:34 PM, Lie Ryan wrote: On 01/01/2012 05:44 AM, davidfx wrote: Thanks for your response. I know the following code is not going to be correct but I want to show you what I was thinking. formatter = %r %r %r %r print formatter % (1, 2, 3, 4) What is the .format version of this

Re: .format vs. %

2011-12-31 Thread Terry Reedy
On 12/31/2011 2:24 PM, Tim Chase wrote: On 12/31/11 12:57, Benjamin Kaplan wrote: format is a method of the string class. You store the string the same way you would any other. formatter = Hello, {} print(formatter.format(world)) Just to note that this syntax doesn't quite work in some