[Python-Dev] Usage of += on strings in loops in stdlib (original) (raw)

Serhiy Storchaka storchaka at gmail.com
Wed Feb 13 15:56:02 CET 2013


On 13.02.13 15:17, Daniel Holth wrote:

On Wed, Feb 13, 2013 at 7:10 AM, Serhiy Storchaka <storchaka at gmail.com_ _<mailto:storchaka at gmail.com>> wrote: I prefer "x = '%s%s%s%s' % (a, b, c, d)" when string's number is more than 3 and some of them are literal strings.

Fixed: x = ('%s' * len(abcd)) % abcd

No, you don't need this for the constant number of strings. Because almost certainly some of strings will be literals, you can write this in a more nice way. Compare:

 'config[' + key + '] = ' + value + '\n'
 ''.join(['config[', key, '] = ', value, '\n'])
 'config[%s] = %s\n' % (key, value)


More information about the Python-Dev mailing list