On 12/31/2011 2:24 PM, Tim Chase wrote:
On 12/31/11 12:57, Benjamin Kaplan wrote:
format is a method of the string class. You store the string the same way
you would any other.

formatter = "Hello, {}"
print(formatter.format("world"))

Just to note that this syntax doesn't quite work in some earlier
versions (tested below in 2.6, which came stock in Debian Stable)

Autonumbering of {} was introduced, at my suggestion, in 3.1 and included with 2.7 (I presume).

 >>> formatter = "Hello, {}"
 >>> print(formatter.format("world"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: zero length field name in format


It needs to be spelled "{0}"

-tkc




--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to