[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-02-12 Thread Terry J. Reedy
New submission from Terry J. Reedy : 3.x str.format() format strings denote replacement fields with braces {}. Currently, replacement fields *must* contain "either the numeric index of a positional argument, or the name of a keyword argument". [lib ref / builtin types / sequence types / string me

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-02-12 Thread Antoine Pitrou
Changes by Antoine Pitrou : -- versions: +Python 2.7 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-02-12 Thread Benjamin Peterson
Changes by Benjamin Peterson : -- nosy: +eric.smith ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-02-12 Thread Eric Smith
Eric Smith added the comment: It's easy enough to implement. Although the 'all-or-nothing' aspect is a little tough, I'll have to give it some thought. Maybe the best way to do this is to first create a string.Formatter subclass that implements it. I'll play with it and see what I come up with.

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-02-12 Thread David W. Lambert
David W. Lambert added the comment: '{d}{s}{f}'.format(3, 'foo', 3.14) is possibly unclear, but is shorter than '{#d}{#s}{#f}'.format(...) -- nosy: +LambertDW ___ Python tracker __

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-02-12 Thread David W. Lambert
David W. Lambert added the comment: I am net yet fluent in format method. I meant ":" where "#" appeared. Anyway, I think you need the colon. If from print('{0:9}'.format(33)) you make the argument number implicit and remove the colon you'd get print('{9}'.format(33)) which does and sho

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-02-12 Thread Eric Smith
Eric Smith added the comment: How is: '{d}{s}{f}'.format(3, 'foo', 3.14) more unclear than: '%d%s%f' % (3, 'foo', 3.14) ? But the more I think about it, the more I think it would have to be: '{:d}{:s}{:f}'.format(3, 'foo', 3.14) Since "{0:0}" is a legitimate format string, I need some way to t

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-02-13 Thread Ezio Melotti
Changes by Ezio Melotti : -- nosy: +ezio.melotti ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.pyt

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-02-13 Thread Mark Dickinson
Mark Dickinson added the comment: +1 for the general idea from me too, assuming that all the details can be worked out in a sane manner. Is it worth opening a discussion about this on comp.lang.python? -- nosy: +marketdickinson ___ Python tracker <

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-02-13 Thread Eric Smith
Eric Smith added the comment: The attached file is a mostly working version that inherits from string.Formatter. It has the following shortcomings, which would all be addressed if we go forward: - Doesn't handle escaping '{' or '}' - Doesn't handle conversion specifiers, like '!s' These are al

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-02-13 Thread Antoine Pitrou
Antoine Pitrou added the comment: Unfortunately, `'{d}{s}{f}'.format(3, 'foo', 3.14)` can't work as you expect it to, because it already means "display the keyword arguments named `d`, `s` and `f`. (I agree that the syntax for format() strings is exceedingly tedious) On the other hand, `'{:d}{

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-02-13 Thread David W. Lambert
David W. Lambert added the comment: Answering first question msg81873. Without colon separator, this might be considered confusing: >>> ( ... '{d}{s}{f}{f}'.format(3, 'foo', 3.14, 2.72), ... '{d}{s}{f}{f}'.format(d=3, s='foo', f=3.14) ... ) ('3foo3.142.72', '3foo3.143.14') ___

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-02-13 Thread Eric Smith
Eric Smith added the comment: Right. The colon would be required if there's a format specifier. Or an exclamation if there's just a conversion specifier: "{!r}{:f}{!s:^10}".format('foo', 3, 10) would give: "'foo'3.0010" I've attached a new version that includes format specifiers.

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-02-13 Thread Terry J. Reedy
Terry J. Reedy added the comment: All I am requesting is that '{} {} {}'.format(3, 'pi', 3.14) work as >>> '%s %s %s' % (3, 'pi', 3.14) '3 pi 3.14' >>> '{0} {1} {2}'.format(3, 'pi', 3.14) '3 pi 3.14' do today (3.0). I should note that the difference between typing {}, which is easy, and {1},

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-02-13 Thread Eric Smith
Eric Smith added the comment: Terry J. Reedy wrote: > Terry J. Reedy added the comment: > > All I am requesting is that > '{} {} {}'.format(3, 'pi', 3.14) work as > '%s %s %s' % (3, 'pi', 3.14) > '3 pi 3.14' '{0} {1} {2}'.format(3, 'pi', 3.14) > '3 pi 3.14' > > do today (3.0). My

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-02-13 Thread Eric Smith
Changes by Eric Smith : -- assignee: -> eric.smith ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-02-14 Thread Eric Smith
Eric Smith added the comment: auto_number_formatter_2.py lets you experiment with this with a syntax more similar to what ''.format() looks like: $ ./python Python 2.7a0 (trunk:69608, Feb 14 2009, 04:51:18) [GCC 4.1.2 20070626 (Red Hat 4.1.2-13)] on linux2 Type "help", "copyright", "credits"

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-02-14 Thread Eric Smith
Eric Smith added the comment: Okay, one last version. This one lets you use object access within the replacement string: >>> from auto_number_formatter_3 import formatter as _ >>> _('{} {} {}').format(3, 'pi', 3.14) '3 pi 3.14' >>> _('{:#b} {!r:^10} {.imag}').format(3, 'pi', 3j+1) "0b11'pi'

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-09 Thread Eric Smith
Eric Smith added the comment: I'm attaching a patch that delivers the basic functionality in str.format. This patch is against trunk, although it will probably work elsewhere. DO NOT USE THIS PATCH IN ANY SERIOUS WORK It doesn't implement all of the needed functionality, it probably has a memo

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-09 Thread Eric Smith
Eric Smith added the comment: Also note that this patch causes a few tests to fail, since they're trying to ensure that '{}'.format will fail. If we go forward I'll address that too, of course. -- message_count: 15.0 -> 16.0 ___ Python tracker

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-09 Thread Guido van Rossum
Guido van Rossum added the comment: Please go ahead and finish this. I'm glad this is going in! -- message_count: 16.0 -> 17.0 nosy: +gvanrossum nosy_count: 6.0 -> 7.0 ___ Python tracker ___

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-09 Thread Nick Coghlan
Nick Coghlan added the comment: Excellent feature - with this, I would actually see some hope for dropping all of my remaining uses of %-formatting at some point in the future. -- message_count: 17.0 -> 18.0 nosy: +ncoghlan nosy_count: 7.0 -> 8.0 ___

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-09 Thread Senthil
Senthil added the comment: Would someone like to point the python-ideas discussion which rationalizes this request? And what would be written in the documentation? As much as I understand this, emptry braces {} for replacement fields is kind of unseen and leaves much thinking if this can be simp

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-10 Thread Ezio Melotti
Ezio Melotti added the comment: http://mail.python.org/pipermail/python-ideas/2009-February/002873.html -- message_count: 19.0 -> 20.0 ___ Python tracker ___

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-10 Thread Nick Coghlan
Nick Coghlan added the comment: Terry covered how to document the feature in his original description of the proposal. After the phrase "either the numeric index of a positional argument, or the name of a keyword argument." in the docs, add a sentence along the lines of the following: "If the

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-10 Thread Nick Coghlan
Nick Coghlan added the comment: It may also be worth explicitly stating the following in the docs: "Note that automatically numbered and explcitly namged/numbered replacement fields cannot be mixed in a single format string". (This could probably be relegated to a footnote). This proposal is al

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-13 Thread Eric Smith
Eric Smith added the comment: I'm thinking of allowing you to mix keywords and auto-numbering, but not manual numbering and auto-numbering. This would be so we could do: >>> '{:{fmt}} {:{fmt}}'.format(3.1415, 2.71828, fmt='1.4f') 'pi=3.1415 e=2.7183' Unfortunately the ':' is required, because

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-13 Thread Eric Smith
Eric Smith added the comment: Copy and paste error. That should be: >>> 'pi={:{fmt}} e={:{fmt}}'.format(3.1415, 2.71828, fmt='1.4f') 'pi=3.1415 e=2.7183' -- ___ Python tracker _

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-13 Thread Eric Smith
Eric Smith added the comment: Should string.Format also support auto-numbering? It seems like it should, but I'm not convinced it's possible without modifying the signatures to the public methods, in particular get_field(). The design of string.Format doesn't support state that is created in fo

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-13 Thread Guido van Rossum
Guido van Rossum added the comment: Not sure if that's worth it -- doesn't sound like the people who would need that feature would mind much using explicit numbering. Let's try KISS. -- ___ Python tracker _

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-13 Thread Guido van Rossum
Guido van Rossum added the comment: (I meant that as a reply to the {:{fmt}} example, but it applies to your later post too. :-) -- ___ Python tracker ___ ___

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-13 Thread Eric Smith
Eric Smith added the comment: I believe this patch is complete. I need to add tests and documentation, but the code itself should be finished. Here's the normal case: >>> '{} {}'.format('test', 0) 'test 0' It also handles error checking: >>> '{1} {}'.format('test', 0) Traceback (most recent ca

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-13 Thread Eric Smith
Eric Smith added the comment: About '{:{fmt}}' and other wacky combinations, like '{.__doc__}': It's much easier and cleaner in the code to allow these cases than it would be to disallow them. And I rather like the '{:{fmt}}' example! I suggest leaving them in. They might be useful, and it mak

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-13 Thread Guido van Rossum
Guido van Rossum added the comment: > About '{:{fmt}}' and other wacky combinations, like '{.__doc__}': > > It's much easier and cleaner in the code to allow these cases than it > would be to disallow them. And I rather like the '{:{fmt}}' example! > > I suggest leaving them in. They might be us

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-13 Thread Nick Coghlan
Nick Coghlan added the comment: Only Formatter.format_field() is particularly hard to override at the moment (for the same reason that __format__() methods are tricky to write). That said, creating a locale aware version of string formatting based on string.Formatter is such an obvious idea that

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-14 Thread Eric Smith
Changes by Eric Smith : Removed file: http://bugs.python.org/file13283/half-baked-not-for-real-use.patch ___ Python tracker ___ ___ Python-bugs

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-14 Thread Eric Smith
Eric Smith added the comment: Committed: r70364 (trunk) r70366 (py3k) The docs still need updating. If anyone with more knowledge of the documentation system than I have would like to tackle those, please feel free! -- priority: -> high resolution: -> accepted __

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-14 Thread Terry J. Reedy
Terry J. Reedy added the comment: Either Brandl or Peterson can and typically will change the .rst source if given the exact new text. For me to write that, I need to know the grammar you actually implemented. Did you, in essence, simply change field_name::= (identifier | integer) ("

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-03-14 Thread Eric Smith
Eric Smith added the comment: I implemented this one: field_name::= (identifier | integer | ) ("." attribute_name | "[" element_index "]")* Which I would have written as: field_name::= (identifier | integer)? ("." attribute_name | "[" element_index "]")* Not that it matters,

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-04-16 Thread Eric Smith
Eric Smith added the comment: Terry, are you still interested in documenting this (please say yes!)? I'm hoping it can be done by the beta release. Thanks. Eric. -- ___ Python tracker _

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-04-16 Thread Terry J. Reedy
Terry J. Reedy added the comment: Yes, added to 'do in next few days' list. -- ___ Python tracker ___ ___ Python-bugs-list mailing lis

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-04-16 Thread Eric Smith
Eric Smith added the comment: Terry J. Reedy wrote: > Terry J. Reedy added the comment: > > Yes, added to 'do in next few days' list. Thanks so much. -- ___ Python tracker ___

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-04-20 Thread Terry J. Reedy
Terry J. Reedy added the comment: Suggested doc change for LibRef / StringServices / string / Format String Syntax 1. In the grammar box, replace the field_name line with " field_name ::= arg_name ("." attribute_name | "[" element_index "]")* arg_name ::= (identifier | integer)? " The c

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-04-21 Thread Eric Smith
Eric Smith added the comment: Thanks, Terry. Your changes look reasonable to me. Can you commit them, or at least convert it to a patch against the existing docs? -- ___ Python tracker _

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-04-21 Thread Terry J. Reedy
Terry J. Reedy added the comment: I am not a committer and cannot make patches. However, I did download http://svn.python.org/view/python/trunk/Doc/library/string.rst?revision=70650&view=markup, as string27.txt, carefully edit using the existing rst format, and upload. I trust you can make the

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-04-21 Thread Terry J. Reedy
Terry J. Reedy added the comment: PS. I first edited http://svn.python.org/view/python/branches/py3k/Doc/library/strings.rst?revision=63803&view=markup but then noticed that this goes in 2.7. My impression is that the procedure is to commit to trunk and then forward port, so I redid it as indic

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-04-21 Thread Eric Smith
Eric Smith added the comment: Thanks, Terry. I think the only changes I'll make are: arg_name: (`identifier` | `integer`)* should be: arg_name: (`identifier` | `integer`)? And leave: conversion: "r" | "s" instead of: conversion: "r" | "s" | "a" because 'a' isn't valid in 2.7. -- ___

[issue5237] Allow auto-numbered replacement fields in str.format() strings

2009-04-21 Thread Eric Smith
Eric Smith added the comment: Documentation changes checked into trunk in r71788 and py3k in r71790. Issue closed. -- status: open -> closed ___ Python tracker ___ _