Re: [Python-Dev] transitioning from % to {} formatting

2009-10-17 Thread Lie Ryan
Michael Foord wrote: Benjamin Peterson wrote: 2009/10/5 Nick Coghlan : So I would agree that method invocation on literals (particularly string literals) is an already established language idiom. And who hasn't ever used 4.56.as_integer_ratio()? :) > I've tried 4.__add__ a few times

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-10 Thread Eric Smith
Nick Coghlan wrote: Benjamin Peterson wrote: 2009/10/8 Eric Smith : Christian Tanzer wrote: IMHO, either the translation is done once and gives identical output or it isn't worth doing at all. I disagree. I doubt even 0.001% of all format strings involve octal formatting. Is it really worth n

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-10 Thread Nick Coghlan
Glenn Linderman wrote: > If you want to replace a C program that produces parsed output in a > given format, and that given format includes leading-0-octal numbers, > then it would be good to have the capability in Python .format, even > though Python itself uses 0o prefix. > > Similar arguments m

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-10 Thread Nick Coghlan
Benjamin Peterson wrote: > 2009/10/8 Eric Smith : >> Christian Tanzer wrote: >>> IMHO, either the translation is done once and gives identical output or >>> it isn't worth doing at all. >> I disagree. I doubt even 0.001% of all format strings involve octal >> formatting. Is it really worth not prov

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-08 Thread Glenn Linderman
On approximately 10/8/2009 7:24 AM, came the following characters from the keyboard of Eric Smith: Vinay Sajip wrote: BTW I sent Eric a private mail re. the "0o" versus "0" issue, to see if it was worth raising an enhancement request on the bug tracker using "O" to generate compatible renderin

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-08 Thread Guido van Rossum
On Thu, Oct 8, 2009 at 10:14 AM, Raymond Hettinger wrote: > Do you think there may be some possible parallel to the -3 option > to flag cases of %-formatting?  If so, that could be helpful. Absolutely. This should be simple, since there's just one or two places where to place the warning. We migh

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-08 Thread Raymond Hettinger
[Christian Tanzer] How do you suppose that maintainers could ever do the transition from %- to {}-formatting manually? [Guido van Rossum] This is pretty much the situation with integer division (you can only recognize it by running the code), Do you think there may be some possible parallel

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-08 Thread Guido van Rossum
On Thu, Oct 8, 2009 at 8:08 AM, Christian Tanzer wrote: > All that talk of deprecating %-formatting makes me really nervous. > %-formatting is pervasive in all existing Python code. > > Without an automatic translator that is 100% accurate, porting all > that code to {}-formatting is not possible.

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-08 Thread Vinay Sajip
Benjamin Peterson python.org> writes: > It's also really easy to just write 0{:o} like my translator does. How does that cope when handed a negative number to format? >>> "%#0o" % -1234 '-02322' >>> "0{0:o}".format(-1234) '0-2322' Regards, Vinay Sajip __

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-08 Thread Benjamin Peterson
2009/10/8 Eric Smith : > Christian Tanzer wrote: >> IMHO, either the translation is done once and gives identical output or >> it isn't worth doing at all. > > I disagree. I doubt even 0.001% of all format strings involve octal > formatting. Is it really worth not providing a transition path if it

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-08 Thread Christian Tanzer
Michael Foord wrote at Thu, 08 Oct 2009 16:56:35 +0100: > > If %-formatting is first deprecated then removed from Python and there > > is no automatic transition path that effectively means that existing > > code using %-formatting is forced to stay at whatever Python version > > was the last one

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-08 Thread Michael Foord
Christian Tanzer wrote: [snip...] IMHO, either the translation is done once and gives identical output or it isn't worth doing at all. I disagree. I doubt even 0.001% of all format strings involve octal formatting. Is it really worth not providing a transition path if it can't cover this

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-08 Thread MRAB
Eric Smith wrote: Vinay Sajip wrote: BTW I sent Eric a private mail re. the "0o" versus "0" issue, to see if it was worth raising an enhancement request on the bug tracker using "O" to generate compatible rendering for octals. I didn't get your message, could you resend?. I was thinking the

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-08 Thread Eric Smith
Benjamin Peterson wrote: 2009/10/8 Eric Smith : Christian Tanzer wrote: IMHO, either the translation is done once and gives identical output or it isn't worth doing at all. I disagree. I doubt even 0.001% of all format strings involve octal formatting. Is it really worth not providing a transi

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-08 Thread Christian Tanzer
Eric Smith wrote at Thu, 08 Oct 2009 10:24:33 -0400: > Vinay Sajip wrote: > > BTW I sent Eric a private mail re. the "0o" versus "0" issue, to see if it > > was > > worth raising an enhancement request on the bug tracker using "O" to > > generate > > compatible rendering for octals. > > I didn't

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-08 Thread Christian Tanzer
Eric Smith wrote at Thu, 08 Oct 2009 10:55:21 -0400: > >>> BTW I sent Eric a private mail re. the "0o" versus "0" issue, to see if > >>> it was > >>> worth raising an enhancement request on the bug tracker using "O" to > >>> generate > >>> compatible rendering for octals. > >> I didn't get your

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-08 Thread Eric Smith
Christian Tanzer wrote: Eric Smith wrote at Thu, 08 Oct 2009 10:24:33 -0400: Vinay Sajip wrote: BTW I sent Eric a private mail re. the "0o" versus "0" issue, to see if it was worth raising an enhancement request on the bug tracker using "O" to generate compatible rendering for octals. I didn'

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-08 Thread Vinay Sajip
> I didn't get your message, could you resend?. Resent, it may have been stopped by your spam filters since it came from my vinay-underscore-sajip-at-red-hyphen-dove-dot-com address. The subject was "Python str.format() and octal formatting compatibility". > I was thinking the same thing, but

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-08 Thread Eric Smith
Vinay Sajip wrote: BTW I sent Eric a private mail re. the "0o" versus "0" issue, to see if it was worth raising an enhancement request on the bug tracker using "O" to generate compatible rendering for octals. I didn't get your message, could you resend?. I was thinking the same thing, but it s

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-08 Thread Vinay Sajip
Nick Coghlan gmail.com> writes: > Vinay's problem above is due to using the wrong alignment flag: ">", > which says to right align everything, instead of "=", which says to left > align the sign character and the numeric prefix with the fill character > inserted in the middle. In this particular

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-08 Thread Nick Coghlan
Antoine Pitrou wrote: > Vinay Sajip yahoo.co.uk> writes: > "%0#8x" % 0x1234 >> '0x001234' > "{0:0>#8x}".format(0x1234) >> '000x1234' > > Apart from the sheer unreadability of the {}-style format string, the result > looks rather unexpected from a human being's point of view. The percent

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-07 Thread Eric Smith
Antoine Pitrou wrote: Vinay Sajip yahoo.co.uk> writes: "%0#8x" % 0x1234 '0x001234' "{0:0>#8x}".format(0x1234) '000x1234' Apart from the sheer unreadability of the {}-style format string, the result looks rather unexpected from a human being's point of view. (in those situations, I would

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-07 Thread Vinay Sajip
Antoine Pitrou pitrou.net> writes: > > Vinay Sajip yahoo.co.uk> writes: > > > > >>> "%0#8x" % 0x1234 > > '0x001234' > > >>> "{0:0>#8x}".format(0x1234) > > '000x1234' > > Apart from the sheer unreadability of the {}-style format string, the result > looks rather unexpected from a human being'

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-07 Thread Antoine Pitrou
Vinay Sajip yahoo.co.uk> writes: > > >>> "%0#8x" % 0x1234 > '0x001234' > >>> "{0:0>#8x}".format(0x1234) > '000x1234' Apart from the sheer unreadability of the {}-style format string, the result looks rather unexpected from a human being's point of view. (in those situations, I would output the

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-07 Thread Benjamin Peterson
2009/10/4 INADA Naoki : > What about using string prefix 'f'? > >  f"{foo} and {bar}" % something == "{foo} and {bar}.format(something) > >  s = f"{foo}" >  t = "%(bar)s" >  s + t  # raises Exception > > Transition plan: > n: Just add F prefix. And adding "format_string" in future. > n+1: deprecate

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-06 Thread Guido van Rossum
On Fri, Oct 2, 2009 at 6:29 PM, Greg Ewing wrote: > Has anyone considered the idea of having the string % operator > behave intelligently according to the contents of the format > string? > > If it contains one or more valid %-formats, use old-style > formatting; if it contains one or more valid {

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-06 Thread Greg Ewing
Martin v. Löwis wrote: So if a decision was made to eventually remove % formatting, it would be reasonable to start migrating code to PEP 3101. However, no such decision has been made (and hopefully won't be throughout 3.x) If it's not done during 3.x, then by the time 4.x comes around, there

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-06 Thread Greg Ewing
Has anyone considered the idea of having the string % operator behave intelligently according to the contents of the format string? If it contains one or more valid %-formats, use old-style formatting; if it contains one or more valid {}-formats, use new-style formatting. Ambiguous cases could a

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-05 Thread Michael Foord
Benjamin Peterson wrote: 2009/10/5 Nick Coghlan : So I would agree that method invocation on literals (particularly string literals) is an already established language idiom. And who hasn't ever used 4.56.as_integer_ratio()? :) I've tried 4.__add__ a few times (not for a while n

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-05 Thread Benjamin Peterson
2009/10/5 Nick Coghlan : > So I would agree that method invocation on literals (particularly string > literals) is an already established language idiom. And who hasn't ever used 4.56.as_integer_ratio()? :) -- Regards, Benjamin ___ Python-Dev mailing

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-05 Thread Benjamin Peterson
2009/10/4 INADA Naoki : >> -1 That requires keeping formatting information around in every string >> instance. > Adding new "format_string" class avoids it. >  unicode("foo") <=> u"foo" >  format_string("foo") <=> f"foo" > > This way's pros: > * Many libraries can use one transition way. > * Trans

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-05 Thread Nick Coghlan
Guido van Rossum wrote: > \>> I hate calling methods on string literals, I think it looks very odd >>> to have code like this: >>> >>> "Displaying {0} of {1} revisions".format(x, y) >> Ugh! Good point. > > This objection was made years ago when we introduced > "separator".join(list_of_things),

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-05 Thread Guido van Rossum
\>> I hate calling methods on string literals, I think it looks very odd >> to have code like this: >> >>   "Displaying {0} of {1} revisions".format(x, y) > > Ugh!  Good point. This objection was made years ago when we introduced "separator".join(list_of_things), and I don't think ignoring it has

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-05 Thread Nick Coghlan
Martin v. Löwis wrote: > That doesn't mean we have to have a transition plan *now*. Creating one > after Python 3.5 is released (i.e. in 2015 or so) might be sufficient. > > To create a transition plan, you first need *consensus* that you > actually do want to transition. I don't think such consen

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-05 Thread Vinay Sajip
MRAB mrabarnett.plus.com> writes: > >>> "{0:#08x}".format(0x1234) > '0x001234' Good call, but here's another case: >>> "%#o" % 0x1234 '011064' I don't see how to automatically convert the "%#o" spec, though of course there are ways of fudging it. The obvious conversion doesn't give the same v

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-05 Thread MRAB
Vinay Sajip wrote: Raymond Hettinger rcn.com> writes: We should get one written. ISTM, every %-formatting string is directly translatable to an equivalent {}-formatting string. I'm not sure you can always get equivalent output from the formatting, though. For example: "%0#8x" % 0x1234 '0x

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-05 Thread Paul Moore
2009/10/5 Vinay Sajip : > Raymond Hettinger rcn.com> writes: >> We should get one written.  ISTM, every %-formatting >> string is directly translatable to an equivalent {}-formatting string. > > I'm not sure you can always get equivalent output from the formatting, though. > For example: > "%

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-05 Thread Vinay Sajip
Raymond Hettinger rcn.com> writes: > We should get one written. ISTM, every %-formatting > string is directly translatable to an equivalent {}-formatting string. I'm not sure you can always get equivalent output from the formatting, though. For example: >>> "%0#8x" % 0x1234 '0x001234' >>> "{0:0

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-05 Thread Nick Coghlan
Vinay Sajip wrote: > Nick Coghlan gmail.com> writes: > >> I'm starting to think that a converter between the two format >> mini-languages may be the way to go though. >> >> fmt_braces is meant to provide a superset of the capabilites of >> fmt_percent, so a forward converter shouldn't be too hard

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-04 Thread Martin v. Löwis
> I agree with this 100% but I can't see it working unless we have some > sort of transition plan. Just saying "ok, switch your format strings > from % to {}" didn't work in Python 3.0 for various good reasons, and > I can't imagine it will work in Python 4.0 unless we have a transition > plan. Th

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-04 Thread Terry Reedy
Carl Trachte wrote: I've skimmed over the PEP, and the new {}-syntax seems to have some nice features. But I've not seen it used anywhere yet. I am using it with 3.1 in an unreleased book I am still writing, and will in any code I publish. Rami Chowdhury posted this to a mailing list; I'

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-04 Thread INADA Naoki
> -1 That requires keeping formatting information around in every string > instance. Adding new "format_string" class avoids it. unicode("foo") <=> u"foo" format_string("foo") <=> f"foo" This way's pros: * Many libraries can use one transition way. * Transition stage syncs to Python version. "l

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-04 Thread INADA Naoki
What about using string prefix 'f'? f"{foo} and {bar}" % something == "{foo} and {bar}.format(something) s = f"{foo}" t = "%(bar)s" s + t # raises Exception Transition plan: n: Just add F prefix. And adding "format_string" in future. n+1: deprecate __mod__() without 'F'. n+2: libraries

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-04 Thread Carl Trachte
>> Do the users get any say in this? > > I'm a user! :-) > > I hate calling methods on string literals, I think it looks very odd to > have code like this: > > "Displaying {0} of {1} revisions".format(x, y) > > Will we be able to write this as > > "Displaying {0} of {1} revisions" % (x, y) > >

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-04 Thread Brett Cannon
On Sat, Oct 3, 2009 at 11:05, Brett Cannon wrote: > On Fri, Oct 2, 2009 at 20:03, Raymond Hettinger wrote: >> >> [Terry Reedy] >>> >>> I would agree, for instance, that an auto-translation tool is needed. >> >> We should get one written.  ISTM, every %-formatting >> string is directly translatabl

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-04 Thread Barry Scott
On 1 Oct 2009, at 10:37, M.-A. Lemburg wrote: Eric Smith wrote: Martin v. Löwis wrote: Steven Bethard wrote: There's a lot of code already out there (in the standard library and other places) that uses %-style formatting, when in Python 3.0 we should be encouraging {}-style formatting. I

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-03 Thread Nick Coghlan
Bugbee, Larry wrote: > So until I see a *significant* benefit, my vote is *not* remove > %-formatting. Make both available and if {} is to win, it will. Percent formatting isn't going anywhere (certainly not for the next decade or so). However, its well documented limitations (especially the lack

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-03 Thread Benjamin Peterson
2009/10/3 Brett Cannon : > On Fri, Oct 2, 2009 at 20:03, Raymond Hettinger wrote: >> >> [Terry Reedy] >>> >>> I would agree, for instance, that an auto-translation tool is needed. >> >> We should get one written.  ISTM, every %-formatting >> string is directly translatable to an equivalent {}-form

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-03 Thread Vinay Sajip
MRAB mrabarnett.plus.com> writes: > Interesting that you're using the %-format to translate %-formats to > {}-formats! Yes, ironic, isn't it? ;-) Regards, Vinay Sajip ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-03 Thread MRAB
Vinay Sajip wrote: Brett Cannon python.org> writes: Why don't we start something in the sandbox and see how far we can get. If no one beats me to it I will add the directory some time today and we can start hashing out the solution there. I've done a first cut of a converter from %-format t

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-03 Thread Benjamin Peterson
2009/10/3 Vinay Sajip : > Raymond Hettinger rcn.com> writes: > >> We should get one written.  ISTM, every %-formatting >> string is directly translatable to an equivalent {}-formatting string. >> > > I've made a start, but I'm not sure how best to handle the '#' and ' ' > conversion flags. Mine h

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-03 Thread Brett Cannon
On Sat, Oct 3, 2009 at 15:27, Vinay Sajip wrote: > Brett Cannon python.org> writes: > >> Why don't we start something in the sandbox and see how far we can >> get. If no one beats me to it I will add the directory some time today >> and we can start hashing out the solution there. >> > > I've don

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-03 Thread Vinay Sajip
Raymond Hettinger rcn.com> writes: > We should get one written. ISTM, every %-formatting > string is directly translatable to an equivalent {}-formatting string. > I've made a start, but I'm not sure how best to handle the '#' and ' ' conversion flags. Regards, Vinay Sajip

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-03 Thread Vinay Sajip
Nick Coghlan gmail.com> writes: > I'm starting to think that a converter between the two format > mini-languages may be the way to go though. > > fmt_braces is meant to provide a superset of the capabilites of > fmt_percent, so a forward converter shouldn't be too hard. A reverse > converter may

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-03 Thread Vinay Sajip
Brett Cannon python.org> writes: > Why don't we start something in the sandbox and see how far we can > get. If no one beats me to it I will add the directory some time today > and we can start hashing out the solution there. > I've done a first cut of a converter from %-format to {}-format str

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-03 Thread Brett Cannon
On Fri, Oct 2, 2009 at 20:03, Raymond Hettinger wrote: > > [Terry Reedy] >> >> I would agree, for instance, that an auto-translation tool is needed. > > We should get one written.  ISTM, every %-formatting > string is directly translatable to an equivalent {}-formatting string. Why don't we start

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-03 Thread Vinay Sajip
Paul Moore gmail.com> writes: > Still tangential, but it seems to me that this discussion has exposed > a couple of areas where the logging interface is less than ideal: > > - The introspection of the format string to delay computing certain > items (Eric's suggestion may be an improvement here)

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-03 Thread Michael Foord
Paul Moore wrote: 2009/10/1 Eric Smith : It's tangential, but in the str.format case you don't want to check for just '{asctime}', because you might want '{asctime:%Y-%m-%d}', for example. But there are ways to delay computing the time until you're sure it's actually being used in the format

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-03 Thread Paul Moore
2009/10/1 Eric Smith : > It's tangential, but in the str.format case you don't want to check for just > '{asctime}', because you might want '{asctime:%Y-%m-%d}', for example. > > But there are ways to delay computing the time until you're sure it's > actually being used in the format string, withou

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-03 Thread Georg Brandl
Bugbee, Larry schrieb: >>> Do the users get any say in this? >> >> I'm a user! :-) >> >> I hate calling methods on string literals, I think it looks very odd to >> have code like this: >> >> "Displaying {0} of {1} revisions".format(x, y) > > Ugh! Good point. > > Is Python to be an easy-to-lea

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread James Y Knight
On Oct 2, 2009, at 2:56 PM, Raymond Hettinger wrote: Do the users get any say in this? I imagine that some people are heavily invested in %-formatting. Because there has been limited uptake on {}-formatting (afaict), we still have limited experience with knowing that it is actually better, less

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread Bugbee, Larry
> > Do the users get any say in this? > > I'm a user! :-) > > I hate calling methods on string literals, I think it looks very odd > to have code like this: > > "Displaying {0} of {1} revisions".format(x, y) Ugh! Good point. Is Python to be an easy-to-learn-and-remember language? I submi

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread Nick Coghlan
Raymond Hettinger wrote: > Because there has been limited uptake on {}-formatting (afaict), > we still have limited experience with knowing that it is actually > better, less error-prone, easier to learn/rember, etc. Outside > a handful of people on this list, I have yet to see anyone adopt > it

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread Terry Reedy
Benjamin Peterson wrote: 2009/10/2 Raymond Hettinger : [Terry Reedy] I would agree, for instance, that an auto-translation tool is needed. We should get one written. ISTM, every %-formatting string is directly translatable to an equivalent {}-formatting string. Yes, but not all are possible

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread Nick Coghlan
Steven Bethard wrote: > On Fri, Oct 2, 2009 at 12:43 PM, Martin Geisler wrote: >> I hate calling methods on string literals, I think it looks very odd to >> have code like this: >> >> "Displaying {0} of {1} revisions".format(x, y) >> >> Will we be able to write this as >> >> "Displaying {0} of {

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread Benjamin Peterson
2009/10/2 Raymond Hettinger : > > [Terry Reedy] >> >> I would agree, for instance, that an auto-translation tool is needed. > > We should get one written.  ISTM, every %-formatting > string is directly translatable to an equivalent {}-formatting string. Yes, but not all are possible to guess with

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread Raymond Hettinger
[Terry Reedy] I would agree, for instance, that an auto-translation tool is needed. We should get one written. ISTM, every %-formatting string is directly translatable to an equivalent {}-formatting string. Raymond ___ Python-Dev mailing list Pyt

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread Terry Reedy
Steven Bethard wrote: On Thu, Oct 1, 2009 at 10:49 PM, Terry Reedy wrote: As someone who likes .format() and who already uses such bound methods to print, such as in emsg = "...".format ... if c: print(emsg(arg, barg)) I find this **MUCH** preferable to the ugly and seemingly unnecessary wr

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread Brett Cannon
On Wed, Sep 30, 2009 at 05:29, Paul Moore wrote: > 2009/9/30 Barry Warsaw : >> Although I hate the name 'dicttemplate', this seems like the best solution >> to me.  Maybe it's good that 'dicttemplate' is so ugly though so that people >> will naturally prefer 'format' :).  But I like this because t

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread Steven Bethard
On Fri, Oct 2, 2009 at 11:56 AM, Raymond Hettinger wrote: > [Steven Bethard] >> Just saying "ok, switch your format strings >> from % to {}" didn't work in Python 3.0 for various good reasons, and >> I can't imagine it will work in Python 4.0 unless we have a transition >> plan. > > Do the users g

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread Steven Bethard
On Fri, Oct 2, 2009 at 12:43 PM, Martin Geisler wrote: > I hate calling methods on string literals, I think it looks very odd to > have code like this: > >  "Displaying {0} of {1} revisions".format(x, y) > > Will we be able to write this as > >  "Displaying {0} of {1} revisions" % (x, y) > > too?

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread Martin Geisler
"Raymond Hettinger" writes: > [Steven Bethard] >>. Just saying "ok, switch your format strings >> from % to {}" didn't work in Python 3.0 for various good reasons, and >> I can't imagine it will work in Python 4.0 unless we have a transition >> plan. > > Do the users get any say in this? I'm a u

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread Antoine Pitrou
Raymond Hettinger rcn.com> writes: > > Because there has been limited uptake on {}-formatting (afaict), > we still have limited experience with knowing that it is actually > better, less error-prone, easier to learn/rember, etc. It is known to be quite slower. The following timings are on the p

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread Raymond Hettinger
[Steven Bethard] . Just saying "ok, switch your format strings from % to {}" didn't work in Python 3.0 for various good reasons, and I can't imagine it will work in Python 4.0 unless we have a transition plan. Do the users get any say in this? I imagine that some people are heavily invested in

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread Steven Bethard
On Fri, Oct 2, 2009 at 2:34 AM, Antoine Pitrou wrote: > Steven Bethard gmail.com> writes: >> >> But it's not much of a transition plan. Or are you suggesting: > > The question is why we want a transition plan that will bother everyone with > no > tangible benefits for the user. I think Guido ex

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread Barry Warsaw
On Oct 2, 2009, at 5:34 AM, Antoine Pitrou wrote: Steven Bethard gmail.com> writes: But it's not much of a transition plan. Or are you suggesting: The question is why we want a transition plan that will bother everyone with no tangible benefits for the user. Forcing a transition to {}-

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread Antoine Pitrou
Steven Bethard gmail.com> writes: > > But it's not much of a transition plan. Or are you suggesting: The question is why we want a transition plan that will bother everyone with no tangible benefits for the user. Regards Antoine. ___ Python-Dev mai

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread Brett Cannon
On Thu, Oct 1, 2009 at 15:19, Steven Bethard wrote: > On Thu, Oct 1, 2009 at 11:03 AM, Brett Cannon wrote: >> So I created this last night: >> >> import collections >> >> class braces_fmt(str): >> >>    def __mod__(self, stuff): >>        if isinstance(stuff, tuple): >>            return self.__c

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-02 Thread Steven Bethard
On Thu, Oct 1, 2009 at 10:49 PM, Terry Reedy wrote: > As someone who likes .format() and who already uses such bound methods to > print, such as in > > emsg = "...".format > ... >   if c: print(emsg(arg, barg)) > > I find this **MUCH** preferable to the ugly and seemingly unnecessary > wrapper cla

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread Terry Reedy
Antoine Pitrou wrote: Vinay Sajip yahoo.co.uk> writes: Does it seems too onerous to expect people to pass an additional "use_format" keyword argument with every logging call to indicate how to interpret the message format string? Or does the PercentMessage/BraceMessage type approach have any mi

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread Steven Bethard
On Thu, Oct 1, 2009 at 4:35 PM, Brett Cannon wrote: > On Thu, Oct 1, 2009 at 15:19, Steven Bethard wrote: >> On Thu, Oct 1, 2009 at 11:03 AM, Brett Cannon wrote: >>> class braces_fmt(str): >>> >>>    def __mod__(self, stuff): >>>        if isinstance(stuff, tuple): >>>            return self.__c

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread Brett Cannon
On Thu, Oct 1, 2009 at 14:54, Nick Coghlan wrote: > Vinay Sajip wrote: >> So there's no need to change modules like logging to explicitly >> provide support for {}-formatting? What's not to like? ;-) Something >> like this perhaps should have been added in at the same time as >> str.format went in

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread James Y Knight
On Oct 1, 2009, at 6:19 PM, Steven Bethard wrote: I see how this could allow a user to supply a {}-format string to an API that accepts only %-format strings. But I still don't see the transition strategy for the API itself. That is, how does the %-format API use this to eventually switch to {}-f

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread Eric Smith
Vinay Sajip wrote: Good point as far as the general case is concerned, though it's perhaps not that critical for logging. By which I mean, it's not unreasonable for Formatter.__init__ to grow a "style" keyword parameter which determines whether it uses %-, {}- or $-formatting. Then the formatter

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread Vinay Sajip
Nick Coghlan gmail.com> writes: > I believe classes like fmt_braces/fmt_dollar/fmt_percent will be part of > a solution, but they aren't a complete solution on their own. (Naming > the three major string formatting techniques by the key symbols involved > is a really good idea though) > > The tw

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread Steven Bethard
On Thu, Oct 1, 2009 at 11:03 AM, Brett Cannon wrote: > So I created this last night: > > import collections > > class braces_fmt(str): > >    def __mod__(self, stuff): >        if isinstance(stuff, tuple): >            return self.__class__(self.format(*stuff)) >        elif isinstance(stuff, coll

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread Vinay Sajip
James Y Knight fuhm.net> writes: > Using containment instead of inheritance makes sure none of the > *other* operations people do on strings will appear to work, at least > (substring, contains, etc). I bet explicitly calling str() on a format > string is even more rare than attempting to d

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread James Y Knight
On Oct 1, 2009, at 5:54 PM, Nick Coghlan wrote: I believe classes like fmt_braces/fmt_dollar/fmt_percent will be part of a solution, but they aren't a complete solution on their own. (Naming the three major string formatting techniques by the key symbols involved is a really good idea though

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread Nick Coghlan
Vinay Sajip wrote: > So there's no need to change modules like logging to explicitly > provide support for {}-formatting? What's not to like? ;-) Something > like this perhaps should have been added in at the same time as > str.format went in. I believe classes like fmt_braces/fmt_dollar/fmt_perce

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread Nick Coghlan
Vinay Sajip wrote: > You're right to be nervous: it's not hard to mangle subtypes. > class mystr(str): pass > ... s = mystr("Abc") s > 'Abc' type(s) > s2 = s.replace("A", "a") s2 > 'abc' type(s2) > It's also difficult for the subclass to prevent this without c

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread Vinay Sajip
> So I created this last night: > > import collections > > class braces_fmt(str): > > def __mod__(self, stuff): > if isinstance(stuff, tuple): > return self.__class__(self.format(*stuff)) > elif isinstance(stuff, collections.Mapping): > return self.__

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread Nick Coghlan
Glenn Linderman wrote: > 1) Both the format message and all the parameters are supplied in a > single API call. This is really a foolish API, because > >def API( fmt, p1, p2, p3 ): > str = fmt % (p1, p2, p3) > > could have just as easily been documented originally as > >def API( str

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread Brett Cannon
On Thu, Oct 1, 2009 at 06:29, Vinay Sajip wrote: > Paul Moore gmail.com> writes: > >> This seems to me to be almost the same as the previous suggestion of >> having a string subclass: >> >> class BraceFormatter(str): >>     def __mod__(self, other): >>         # Needs more magic here to cope with

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread Glenn Linderman
On approximately 9/30/2009 4:03 PM, came the following characters from the keyboard of Vinay Sajip: Steven Bethard gmail.com> writes: There's a lot of code already out there (in the standard library and other places) that uses %-style formatting, when in Python 3.0 we should be encouraging {}-

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread Vinay Sajip
Raymond Hettinger rcn.com> writes: > It looks like the BraceMessage would have to re-instantiate on every > invocation. True, because the arguments to the instantiation are kept around as a BraceMessage instance until the time comes to actually format the message (which might be never). Since ty

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread James Y Knight
On Sep 30, 2009, at 1:01 PM, Antoine Pitrou wrote: Why not allow logging.Formatter to take a callable, which would in turn call the callable with keyword arguments? Therefore, you could write: logging.Formatter("{asctime} - {name} - {level} - {msg}".format) and then: logging.critical(name

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread Raymond Hettinger
[Vinay Sajip] And the special wrappers needn't be too intrusive: __ = BraceMessage logger.debug(__("Message with {0} {1}", 1, "argument")) It looks like the BraceMessage would have to re-instantiate on every invocation. Raymond ___ Python-Dev mai

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread James Y Knight
On Oct 1, 2009, at 9:11 AM, Paul Moore wrote: This seems to me to be almost the same as the previous suggestion of having a string subclass: class BraceFormatter(str): def __mod__(self, other): # Needs more magic here to cope with dict argument return self.format(*other) __ =

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread Vinay Sajip
Antoine Pitrou pitrou.net> writes: > There's another possibility, which is to build the wrapping directly around > the > logger. That is, if I want a %-style logger, I do: > >logger = logging.getLogger("smtp") >logger.debug("incoming email from %s", sender_address) > > and I want a {}-

Re: [Python-Dev] transitioning from % to {} formatting

2009-10-01 Thread Vinay Sajip
Paul Moore gmail.com> writes: > 2. The internal implementation of logger.debug needs to preserve > string subclasses properly > > But the benefit is that the approach allows anyone to use brace > formatting in any API that currently accepts % format (assuming string > subclasses don't get mangle

  1   2   >