This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.smith
Recipients LambertDW, eric.smith, ezio.melotti, mark.dickinson, pitrou, terry.reedy
Date 2009-03-09.12:16:57
SpamBayes Score 0.0
Marked as misclassified No
Message-id <1236601024.52.0.909780562423.issue5237@psf.upfronthosting.co.za>
In-reply-to
Content
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
memory leak, and it most likely can cause a GP fault. It does, however,
handle the common cases and it will give you a taste of the feature.

In particular, it doesn't handle anything other than empty braces
('{:d}' will fail). I can add this, and I think it should be added, but
I just haven't had the time to finish it up. I wanted to get this posted
so others can play with it and we can reach a decision if we want to add
this functionality. Personally, I think it's a great improvement, and
the more I play with it the more I like it.

If we reach a consensus that the feature should be added, I can probably
get it cleaned up and finished before PyCon.

$ ./python.exe 
Python 2.7a0 (trunk:70244M, Mar  8 2009, 16:54:23) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> '{} {} {}'.format(1, 3.4, 'test')
'1 3.4 test'
>>> '{} {1}'.format(1, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: cannot switch from automatic field numbering to manual field
specification
>>>
History
Date User Action Args
2009-03-09 12:17:04eric.smithsetrecipients: + eric.smith, terry.reedy, mark.dickinson, pitrou, LambertDW, ezio.melotti
2009-03-09 12:17:04eric.smithsetmessageid: <1236601024.52.0.909780562423.issue5237@psf.upfronthosting.co.za>
2009-03-09 12:17:02eric.smithlinkissue5237 messages
2009-03-09 12:17:00eric.smithcreate