PEP 378: Format Specifier for Thousands Separator
Jerry Hill
malaclypse2 at gmail.com
Thu May 23 21:17:54 EDT 2013
On Thu, May 23, 2013 at 6:20 PM, Carlos Nepomuceno <
carlosnepomuceno at outlook.com> wrote:
> Can str.format() do the following?
>
> f = '%d %d %d'
> v = '1,2,3'
> print f % eval(v)
>
Sure:
Python 3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)]
on win32
>>> f = "{} {} {}"
>>> v = "1,2,3"
>>> print(f.format(*eval(v)))
1 2 3
>>>
The * unpacks the tuple returned from eval(), so that you get 3 separate
parameters passed to format(), instead of the single tuple.
--
Jerry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130523/363fbc73/attachment.html>
More information about the Python-list
mailing list