result = r"\mathjax{{color}}{{text}}".format(color = "blue" , text = "Spanish")
result = "\mathjax{blue}{Spanish}"
Can we change str.format so that it is possible to change only one string parameter, but leave the other parameters alone?
# pfr is partially_formatted_result
pfr = r"\mathjax{{color}}{{text}}".format(color = "blue") # ERROR! missing parameter `text`
result = r"\mathjax{{color}}{{text}}".format(text = "Spanish") # ERROR! missing parameter `color`
The implementation requires fewer than ten lines of code in python, probably less than fifty lines in C, or a different implementation language.
class str:
def format(self, **kwargs):
for key in kwargs:
x = "{"+key+"}"
ostr = kwargs[key].join(self.split(x))
return ostr # output string
As an example, everywhere a string contained `{text}` it will now say `Spanish` .