On Fri, 06 May 2011 10:00:30 +0200, Web Dreamer wrote: > Jabba Laci a écrit ce vendredi 6 mai 2011 09:18 dans > <mailman.1229.1304666321.9059.python-l...@python.org> : > >> Hi, >> >> Which is the preferred way of string formatting? >> >> (1) "the %s is %s" % ('sky', 'blue') >> >> (2) "the {0} is {1}".format('sky', 'blue') >> >> (3) "the {} is {}".format('sky', 'blue') >> >> As I know (1) is old style. (2) and (3) are new but (3) is only >> supported from Python 2.7+. >> >> Which one should be used? > > According to python's documentation, (3) and (2) are preferred and (1) > is deprecated.
I think you are wrong, % formatting is not deprecated. Do you have a link showing otherwise? [steve@sylar ~]$ python3.2 Python 3.2a1 (r32a1:83318, Aug 12 2010, 02:17:22) [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> import warnings >>> warnings.simplefilter("always") >>> "%d" % 42 '42' I see no DeprecationWarning. -- Steven -- http://mail.python.org/mailman/listinfo/python-list