Django, for example, uses this code to cater for ValidationError exceptions
>>> message = 'My name is %(name)s'
>>> params = {'name': 'George'}
>>> message %= params
>>> print(message):
'My name is George'
The only documentation I managed to find on %= is here where it is called a modulus assignment operator.
I really do not understand why it works with the old style formatting (%) and I cannot understand how this will be used with the new style formatting (str.format()).
Does the new style formatting render this code redundant?
x = x%yso it makes sense that it works. And yes,%style formatting is pretty old and you should use new style formatting__mod__, that method will define how the instances of the class will behave when operated with%operator. There is more information about this subject in this question%=works. For the new style, old style I am refering to % vs str.format().str.formatis a workaround, some kind of wrapper function to prevent some funny use cases of%operator with strings. The first answer of the question you linked shows a use-case with tuples (useful to parse multiple values at once into strings), where, to prevent TypeMismatch errors, you "hack" a single value as a 1-len tuple. The newformatmethod probably wraps the original functionality to prevent this kind of cases right away, among other things, which helps to write cleaner code. And that's great.%=operator in the new formatting but at the same time this is not redundant, it is just old fashioned.