, .
, DRY , , :
- , . ,
logging, web2py gettext. - .
- .
, , foo : "%(foo)s" % dict(foo=foo). . , , .
The second method is the easiest method, and this is what you usually use in most programs. This is best used when the format string is immediate, for example. 'values: %s %s %s' % (a, b, c)instead of taking from a variable, for example. fmt % (a, b, c).
The first concatenation is almost never useful, except, perhaps, if you create a list in cycles:
s = ''
for x in l:
s += str(x)
however, in this case, it is generally better and faster to use str.join ():
s = ''.join(str(x) for x in l)
source
share