On 13/11/2012 4:18 PM, Dave Angel
wrote:
On 11/13/2012 03:24 PM, Colin J. Williams wrote:<SNIP>I am working on the assumption that the first argument of the format builtin function and be a sequence of values, which can be selected with {1:}, {2:}, {0:} etc. The docs don't make this clear. I would appreciate advice.The built-in function format(): http://docs.python.org/3.3/library/functions.html?highlight=format%20builtin#format The first parameter is a single object, NOT a sequence. One object, one format. If you want more generality, use the str.format() method: http://docs.python.org/3.3/library/stdtypes.html?highlight=format#str.format where you can supply a list or a dictionary of multiple items to be formatted into a single string. That's the one where you supply the curly braces. The docs for the first case leave open the possibility of using a sequence when they say: "Convert a value to a “formatted” representation, as controlled by format_spec. The interpretation of format_spec will depend on the type of the value argument, however there is a standard formatting syntax that is used by most built-in types: Format Specification Mini-Language."I hope that, as time goes by, consideration will be given to permitting a sequence. It would appear to be a relatively simple change. This would extend the generality of the format function. Thanks for clarifying this. It confirmed my trial and error results. Colin W. |
-- http://mail.python.org/mailman/listinfo/python-list